du: dietlibc compat fix, style fixes. Thanks to sampo@symlabs.com.

This commit is contained in:
Denis Vlasenko 2006-12-18 21:22:16 +00:00
parent fcfe834d50
commit f42ff90453

View File

@ -25,26 +25,22 @@
#include "busybox.h" #include "busybox.h"
#ifdef CONFIG_FEATURE_HUMAN_READABLE #if ENABLE_FEATURE_HUMAN_READABLE
# ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K # if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned long disp_hr = 1024; static unsigned long disp_hr = 1024;
# else # else
static unsigned long disp_hr = 512; static unsigned long disp_hr = 512;
# endif # endif
#elif defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K #elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned int disp_k = 1; static unsigned disp_k = 1;
#else #else
static unsigned int disp_k; /* bss inits to 0 */ static unsigned disp_k; /* bss inits to 0 */
#endif #endif
static int max_print_depth = INT_MAX; static int max_print_depth = INT_MAX;
static nlink_t count_hardlinks = 1; static nlink_t count_hardlinks = 1;
static int status static int status;
#if EXIT_SUCCESS == 0
= EXIT_SUCCESS
#endif
;
static int print_files; static int print_files;
static int slink_depth; static int slink_depth;
static int du_depth; static int du_depth;
@ -55,7 +51,7 @@ static dev_t dir_dev;
static void print(long size, const char * const filename) static void print(long size, const char * const filename)
{ {
/* TODO - May not want to defer error checking here. */ /* TODO - May not want to defer error checking here. */
#ifdef CONFIG_FEATURE_HUMAN_READABLE #if ENABLE_FEATURE_HUMAN_READABLE
printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
filename); filename);
#else #else
@ -73,7 +69,7 @@ static long du(const char * const filename)
struct stat statbuf; struct stat statbuf;
long sum; long sum;
if ((lstat(filename, &statbuf)) != 0) { if (lstat(filename, &statbuf) != 0) {
bb_perror_msg("%s", filename); bb_perror_msg("%s", filename);
status = EXIT_FAILURE; status = EXIT_FAILURE;
return 0; return 0;
@ -91,7 +87,7 @@ static long du(const char * const filename)
if (S_ISLNK(statbuf.st_mode)) { if (S_ISLNK(statbuf.st_mode)) {
if (slink_depth > du_depth) { /* -H or -L */ if (slink_depth > du_depth) { /* -H or -L */
if ((stat(filename, &statbuf)) != 0) { if (stat(filename, &statbuf) != 0) {
bb_perror_msg("%s", filename); bb_perror_msg("%s", filename);
status = EXIT_FAILURE; status = EXIT_FAILURE;
return 0; return 0;
@ -130,7 +126,7 @@ static long du(const char * const filename)
char *name = entry->d_name; char *name = entry->d_name;
newfile = concat_subpath_file(filename, name); newfile = concat_subpath_file(filename, name);
if(newfile == NULL) if (newfile == NULL)
continue; continue;
++du_depth; ++du_depth;
sum += du(newfile); sum += du(newfile);
@ -155,9 +151,9 @@ int du_main(int argc, char **argv)
char *smax_print_depth; char *smax_print_depth;
unsigned opt; unsigned opt;
#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K #if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
#ifdef CONFIG_FEATURE_HUMAN_READABLE #if ENABLE_FEATURE_HUMAN_READABLE
disp_hr = 512; disp_hr = 512;
#else #else
disp_k = 0; disp_k = 0;
@ -171,55 +167,55 @@ int du_main(int argc, char **argv)
* gnu du exits with an error code in this case. We choose to simply * 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. * ignore -a. This is consistent with -s being equivalent to -d 0.
*/ */
#ifdef CONFIG_FEATURE_HUMAN_READABLE #if ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
if((opt & (1 << 9))) { if (opt & (1 << 9)) {
/* -h opt */ /* -h opt */
disp_hr = 0; disp_hr = 0;
} }
if((opt & (1 << 10))) { if (opt & (1 << 10)) {
/* -m opt */ /* -m opt */
disp_hr = 1024*1024; disp_hr = 1024*1024;
} }
if((opt & (1 << 2))) { if (opt & (1 << 2)) {
/* -k opt */ /* -k opt */
disp_hr = 1024; disp_hr = 1024;
} }
#else #else
opt_complementary = "H-L:L-H:s-d:d-s"; opt_complementary = "H-L:L-H:s-d:d-s";
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if((opt & (1 << 2))) { if (opt & (1 << 2)) {
/* -k opt */ /* -k opt */
disp_k = 1; disp_k = 1;
} }
#endif #endif
#endif #endif
if((opt & (1 << 0))) { if (opt & (1 << 0)) {
/* -a opt */ /* -a opt */
print_files = INT_MAX; print_files = INT_MAX;
} }
if((opt & (1 << 1))) { if (opt & (1 << 1)) {
/* -H opt */ /* -H opt */
slink_depth = 1; slink_depth = 1;
} }
if((opt & (1 << 3))) { if (opt & (1 << 3)) {
/* -L opt */ /* -L opt */
slink_depth = INT_MAX; slink_depth = INT_MAX;
} }
if((opt & (1 << 4))) { if (opt & (1 << 4)) {
/* -s opt */ /* -s opt */
max_print_depth = 0; max_print_depth = 0;
} }
one_file_system = opt & (1 << 5); /* -x opt */ one_file_system = opt & (1 << 5); /* -x opt */
if((opt & (1 << 6))) { if (opt & (1 << 6)) {
/* -d opt */ /* -d opt */
max_print_depth = xatoi_u(smax_print_depth); max_print_depth = xatoi_u(smax_print_depth);
} }
if((opt & (1 << 7))) { if (opt & (1 << 7)) {
/* -l opt */ /* -l opt */
count_hardlinks = INT_MAX; count_hardlinks = MAXINT(nlink_t);
} }
print_final_total = opt & (1 << 8); /* -c opt */ print_final_total = opt & (1 << 8); /* -c opt */
@ -238,7 +234,7 @@ int du_main(int argc, char **argv)
total += du(*argv); total += du(*argv);
slink_depth = slink_depth_save; slink_depth = slink_depth_save;
} while (*++argv); } while (*++argv);
#ifdef CONFIG_FEATURE_CLEAN_UP #if ENABLE_FEATURE_CLEAN_UP
reset_ino_dev_hashtable(); reset_ino_dev_hashtable();
#endif #endif