#endif
static int max_print_depth = INT_MAX;
-static int count_hardlinks = INT_MAX;
+static int count_hardlinks = 1;
static int status
#if EXIT_SUCCESS == 0
bb_printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
filename);
#else
- bb_printf("%ld\t%s\n", size >> disp_k, filename);
+ if (disp_k) {
+ size++;
+ size >>= 1;
+ }
+ bb_printf("%ld\t%s\n", size, filename);
#endif
}
{
long total;
int slink_depth_save;
- int print_final_total = 0;
- int c;
+ int print_final_total;
+ char *smax_print_depth;
+ unsigned long opt;
#ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
#else
disp_k = 0;
#endif
- }
+ }
#endif
/* Note: SUSv3 specifies that -a and -s options can not be used together
* gnu du exits with an error code in this case. We choose to simply
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
-
- while ((c = getopt(argc, argv, "aHkLsx" "d:" "lc"
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- "hm"
-#endif
- )) > 0) {
- switch (c) {
- case 'a':
- print_files = INT_MAX;
- break;
- case 'H':
- slink_depth = 1;
- break;
- case 'k':
#ifdef CONFIG_FEATURE_HUMAN_READABLE
+ bb_opt_complementally = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
+ opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
+ if((opt & (1 << 9))) {
+ /* -h opt */
+ disp_hr = 0;
+ }
+ if((opt & (1 << 10))) {
+ /* -m opt */
+ disp_hr = MEGABYTE;
+ }
+ if((opt & (1 << 2))) {
+ /* -k opt */
disp_hr = KILOBYTE;
-#elif !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
+ }
+#else
+ bb_opt_complementally = "H-L:L-H:s-d:d-s";
+ opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
+#if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
+ if((opt & (1 << 2))) {
+ /* -k opt */
disp_k = 1;
+ }
#endif
- break;
- case 'L':
+#endif
+ if((opt & (1 << 0))) {
+ /* -a opt */
+ print_files = INT_MAX;
+ }
+ if((opt & (1 << 1))) {
+ /* -H opt */
+ slink_depth = 1;
+ }
+ if((opt & (1 << 3))) {
+ /* -L opt */
slink_depth = INT_MAX;
- break;
- case 's':
+ }
+ if((opt & (1 << 4))) {
+ /* -s opt */
max_print_depth = 0;
- break;
- case 'x':
- one_file_system = 1;
- break;
-
- case 'd':
- max_print_depth = bb_xgetularg10_bnd(optarg, 0, INT_MAX);
- break;
- case 'l':
- count_hardlinks = 1;
- break;
- case 'c':
- print_final_total = 1;
- break;
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- case 'h':
- disp_hr = 0;
- break;
- case 'm':
- disp_hr = MEGABYTE;
- break;
-#endif
- default:
- bb_show_usage();
}
+ one_file_system = opt & (1 << 5); /* -x opt */
+ if((opt & (1 << 6))) {
+ /* -d opt */
+ max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX);
}
+ if((opt & (1 << 7))) {
+ /* -l opt */
+ count_hardlinks = INT_MAX;
+ }
+ print_final_total = opt & (1 << 8); /* -c opt */
/* go through remaining args (if any) */
argv += optind;
total += du(*argv);
slink_depth = slink_depth_save;
} while (*++argv);
+#ifdef CONFIG_FEATURE_CLEAN_UP
reset_ino_dev_hashtable();
+#endif
if (print_final_total) {
print(total, "total");