* Mini du implementation for busybox
*
*
- * Copyright (C) 1999,2000 by Lineo, inc.
+ * Copyright (C) 1999,2000,2001 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
*
*/
-#include "busybox.h"
-#define BB_DECLARE_EXTERN
-#define bb_need_name_too_long
-#include "messages.c"
-
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
+#include <string.h>
#include <errno.h>
+#include "busybox.h"
+#define BB_DECLARE_EXTERN
+#define bb_need_name_too_long
+#include "messages.c"
+
#ifdef BB_FEATURE_HUMAN_READABLE
-unsigned long du_disp_hr = KILOBYTE;
+static unsigned long disp_hr = KILOBYTE;
#endif
typedef void (Display) (long, char *);
static void print_normal(long size, char *filename)
{
+ unsigned long base;
#ifdef BB_FEATURE_HUMAN_READABLE
- printf("%s\t%s\n", format((size * KILOBYTE), du_disp_hr), filename);
+ switch (disp_hr) {
+ case MEGABYTE:
+ base = KILOBYTE;
+ break;
+ case KILOBYTE:
+ base = 1;
+ break;
+ default:
+ base = 0;
+ }
+ printf("%s\t%s\n", make_human_readable_str(size, base), filename);
#else
printf("%ld\t%s\n", size, filename);
#endif
static void print_summary(long size, char *filename)
{
if (du_depth == 1) {
-printf("summary\n");
+ printf("summary\n");
print_normal(size, filename);
}
}
count_hardlinks = 1;
break;
#ifdef BB_FEATURE_HUMAN_READABLE
- case 'h': du_disp_hr = 0; break;
- case 'm': du_disp_hr = MEGABYTE; break;
- case 'k': du_disp_hr = KILOBYTE; break;
-#else
- case 'k': break;
+ case 'h': disp_hr = 0; break;
+ case 'm': disp_hr = MEGABYTE; break;
#endif
+ case 'k': break;
default:
- usage(du_usage);
+ show_usage();
}
}
return status;
}
-/* $Id: du.c,v 1.35 2001/01/27 08:24:37 andersen Exp $ */
+/* $Id: du.c,v 1.43 2001/03/09 14:36:42 andersen Exp $ */
/*
Local Variables:
c-file-style: "linux"