diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-18 21:22:16 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-18 21:22:16 +0000 |
commit | f42ff90453687624874c1eb8cc53f68514f7cb34 (patch) | |
tree | 59c792cf7f48f8a829f948cb526e758bbd3080fb /coreutils/du.c | |
parent | fcfe834d501b1bd0de45c7cb39ca0a259177934f (diff) | |
download | busybox-w32-f42ff90453687624874c1eb8cc53f68514f7cb34.tar.gz busybox-w32-f42ff90453687624874c1eb8cc53f68514f7cb34.tar.bz2 busybox-w32-f42ff90453687624874c1eb8cc53f68514f7cb34.zip |
du: dietlibc compat fix, style fixes. Thanks to sampo@symlabs.com.
Diffstat (limited to 'coreutils/du.c')
-rw-r--r-- | coreutils/du.c | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/coreutils/du.c b/coreutils/du.c index a547b1e14..a1ca5b59b 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -25,26 +25,22 @@ | |||
25 | 25 | ||
26 | #include "busybox.h" | 26 | #include "busybox.h" |
27 | 27 | ||
28 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 28 | #if ENABLE_FEATURE_HUMAN_READABLE |
29 | # ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 29 | # if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
30 | static unsigned long disp_hr = 1024; | 30 | static unsigned long disp_hr = 1024; |
31 | # else | 31 | # else |
32 | static unsigned long disp_hr = 512; | 32 | static unsigned long disp_hr = 512; |
33 | # endif | 33 | # endif |
34 | #elif defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 34 | #elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
35 | static unsigned int disp_k = 1; | 35 | static unsigned disp_k = 1; |
36 | #else | 36 | #else |
37 | static unsigned int disp_k; /* bss inits to 0 */ | 37 | static unsigned disp_k; /* bss inits to 0 */ |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | static int max_print_depth = INT_MAX; | 40 | static int max_print_depth = INT_MAX; |
41 | static nlink_t count_hardlinks = 1; | 41 | static nlink_t count_hardlinks = 1; |
42 | 42 | ||
43 | static int status | 43 | static int status; |
44 | #if EXIT_SUCCESS == 0 | ||
45 | = EXIT_SUCCESS | ||
46 | #endif | ||
47 | ; | ||
48 | static int print_files; | 44 | static int print_files; |
49 | static int slink_depth; | 45 | static int slink_depth; |
50 | static int du_depth; | 46 | static int du_depth; |
@@ -55,9 +51,9 @@ static dev_t dir_dev; | |||
55 | static void print(long size, const char * const filename) | 51 | static void print(long size, const char * const filename) |
56 | { | 52 | { |
57 | /* TODO - May not want to defer error checking here. */ | 53 | /* TODO - May not want to defer error checking here. */ |
58 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 54 | #if ENABLE_FEATURE_HUMAN_READABLE |
59 | printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), | 55 | printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), |
60 | filename); | 56 | filename); |
61 | #else | 57 | #else |
62 | if (disp_k) { | 58 | if (disp_k) { |
63 | size++; | 59 | size++; |
@@ -73,7 +69,7 @@ static long du(const char * const filename) | |||
73 | struct stat statbuf; | 69 | struct stat statbuf; |
74 | long sum; | 70 | long sum; |
75 | 71 | ||
76 | if ((lstat(filename, &statbuf)) != 0) { | 72 | if (lstat(filename, &statbuf) != 0) { |
77 | bb_perror_msg("%s", filename); | 73 | bb_perror_msg("%s", filename); |
78 | status = EXIT_FAILURE; | 74 | status = EXIT_FAILURE; |
79 | return 0; | 75 | return 0; |
@@ -91,7 +87,7 @@ static long du(const char * const filename) | |||
91 | 87 | ||
92 | if (S_ISLNK(statbuf.st_mode)) { | 88 | if (S_ISLNK(statbuf.st_mode)) { |
93 | if (slink_depth > du_depth) { /* -H or -L */ | 89 | if (slink_depth > du_depth) { /* -H or -L */ |
94 | if ((stat(filename, &statbuf)) != 0) { | 90 | if (stat(filename, &statbuf) != 0) { |
95 | bb_perror_msg("%s", filename); | 91 | bb_perror_msg("%s", filename); |
96 | status = EXIT_FAILURE; | 92 | status = EXIT_FAILURE; |
97 | return 0; | 93 | return 0; |
@@ -130,7 +126,7 @@ static long du(const char * const filename) | |||
130 | char *name = entry->d_name; | 126 | char *name = entry->d_name; |
131 | 127 | ||
132 | newfile = concat_subpath_file(filename, name); | 128 | newfile = concat_subpath_file(filename, name); |
133 | if(newfile == NULL) | 129 | if (newfile == NULL) |
134 | continue; | 130 | continue; |
135 | ++du_depth; | 131 | ++du_depth; |
136 | sum += du(newfile); | 132 | sum += du(newfile); |
@@ -155,9 +151,9 @@ int du_main(int argc, char **argv) | |||
155 | char *smax_print_depth; | 151 | char *smax_print_depth; |
156 | unsigned opt; | 152 | unsigned opt; |
157 | 153 | ||
158 | #ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K | 154 | #if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
159 | if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ | 155 | if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ |
160 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 156 | #if ENABLE_FEATURE_HUMAN_READABLE |
161 | disp_hr = 512; | 157 | disp_hr = 512; |
162 | #else | 158 | #else |
163 | disp_k = 0; | 159 | disp_k = 0; |
@@ -171,55 +167,55 @@ int du_main(int argc, char **argv) | |||
171 | * gnu du exits with an error code in this case. We choose to simply | 167 | * gnu du exits with an error code in this case. We choose to simply |
172 | * ignore -a. This is consistent with -s being equivalent to -d 0. | 168 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
173 | */ | 169 | */ |
174 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 170 | #if ENABLE_FEATURE_HUMAN_READABLE |
175 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; | 171 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; |
176 | opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); | 172 | opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); |
177 | if((opt & (1 << 9))) { | 173 | if (opt & (1 << 9)) { |
178 | /* -h opt */ | 174 | /* -h opt */ |
179 | disp_hr = 0; | 175 | disp_hr = 0; |
180 | } | 176 | } |
181 | if((opt & (1 << 10))) { | 177 | if (opt & (1 << 10)) { |
182 | /* -m opt */ | 178 | /* -m opt */ |
183 | disp_hr = 1024*1024; | 179 | disp_hr = 1024*1024; |
184 | } | 180 | } |
185 | if((opt & (1 << 2))) { | 181 | if (opt & (1 << 2)) { |
186 | /* -k opt */ | 182 | /* -k opt */ |
187 | disp_hr = 1024; | 183 | disp_hr = 1024; |
188 | } | 184 | } |
189 | #else | 185 | #else |
190 | opt_complementary = "H-L:L-H:s-d:d-s"; | 186 | opt_complementary = "H-L:L-H:s-d:d-s"; |
191 | opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); | 187 | opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth); |
192 | #if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K | 188 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
193 | if((opt & (1 << 2))) { | 189 | if (opt & (1 << 2)) { |
194 | /* -k opt */ | 190 | /* -k opt */ |
195 | disp_k = 1; | 191 | disp_k = 1; |
196 | } | 192 | } |
197 | #endif | 193 | #endif |
198 | #endif | 194 | #endif |
199 | if((opt & (1 << 0))) { | 195 | if (opt & (1 << 0)) { |
200 | /* -a opt */ | 196 | /* -a opt */ |
201 | print_files = INT_MAX; | 197 | print_files = INT_MAX; |
202 | } | 198 | } |
203 | if((opt & (1 << 1))) { | 199 | if (opt & (1 << 1)) { |
204 | /* -H opt */ | 200 | /* -H opt */ |
205 | slink_depth = 1; | 201 | slink_depth = 1; |
206 | } | 202 | } |
207 | if((opt & (1 << 3))) { | 203 | if (opt & (1 << 3)) { |
208 | /* -L opt */ | 204 | /* -L opt */ |
209 | slink_depth = INT_MAX; | 205 | slink_depth = INT_MAX; |
210 | } | 206 | } |
211 | if((opt & (1 << 4))) { | 207 | if (opt & (1 << 4)) { |
212 | /* -s opt */ | 208 | /* -s opt */ |
213 | max_print_depth = 0; | 209 | max_print_depth = 0; |
214 | } | 210 | } |
215 | one_file_system = opt & (1 << 5); /* -x opt */ | 211 | one_file_system = opt & (1 << 5); /* -x opt */ |
216 | if((opt & (1 << 6))) { | 212 | if (opt & (1 << 6)) { |
217 | /* -d opt */ | 213 | /* -d opt */ |
218 | max_print_depth = xatoi_u(smax_print_depth); | 214 | max_print_depth = xatoi_u(smax_print_depth); |
219 | } | 215 | } |
220 | if((opt & (1 << 7))) { | 216 | if (opt & (1 << 7)) { |
221 | /* -l opt */ | 217 | /* -l opt */ |
222 | count_hardlinks = INT_MAX; | 218 | count_hardlinks = MAXINT(nlink_t); |
223 | } | 219 | } |
224 | print_final_total = opt & (1 << 8); /* -c opt */ | 220 | print_final_total = opt & (1 << 8); /* -c opt */ |
225 | 221 | ||
@@ -238,7 +234,7 @@ int du_main(int argc, char **argv) | |||
238 | total += du(*argv); | 234 | total += du(*argv); |
239 | slink_depth = slink_depth_save; | 235 | slink_depth = slink_depth_save; |
240 | } while (*++argv); | 236 | } while (*++argv); |
241 | #ifdef CONFIG_FEATURE_CLEAN_UP | 237 | #if ENABLE_FEATURE_CLEAN_UP |
242 | reset_ino_dev_hashtable(); | 238 | reset_ino_dev_hashtable(); |
243 | #endif | 239 | #endif |
244 | 240 | ||