summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-03 20:05:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-03 20:05:58 +0000
commit21b83cfb275e723559559c24e8df22a7dc5723a9 (patch)
tree06b4fc5aed8c9e100be60be2a0754b611b3e8d79 /coreutils
parent82f3b16713dd43d25ecd25efc1dc67d00c81af73 (diff)
downloadbusybox-w32-21b83cfb275e723559559c24e8df22a7dc5723a9.tar.gz
busybox-w32-21b83cfb275e723559559c24e8df22a7dc5723a9.tar.bz2
busybox-w32-21b83cfb275e723559559c24e8df22a7dc5723a9.zip
du: remove statics (by Bernhard Fischer <rep.dot.nop@gmail.com>)
$ ./.cmk bloatcheck function old new delta du_main 340 348 +8 print 39 40 +1 status 129 125 -4 slink_depth 4 - -4 print_files 4 - -4 one_file_system 4 - -4 max_print_depth 4 - -4 du_depth 4 - -4 disp_hr 4 - -4 count_hardlinks 4 - -4 du 407 401 -6 dir_dev 8 - -8 ------------------------------------------------------------------------------ (add/remove: 0/8 grow/shrink: 2/2 up/down: 9/-46) Total: -37 bytes text data bss dec hex filename 864 12 28 904 388 busybox.t3/coreutils/du.o 867 0 0 867 363 busybox.t4/coreutils/du.o 770647 1063 10788 782498 bf0a2 busybox.t3/busybox_unstripped 770651 1051 10764 782466 bf082 busybox.t4/busybox_unstripped
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/du.c128
1 files changed, 64 insertions, 64 deletions
diff --git a/coreutils/du.c b/coreutils/du.c
index 757fa14cc..b5e68d8f8 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -25,37 +25,34 @@
25 25
26#include "libbb.h" 26#include "libbb.h"
27 27
28struct globals {
28#if ENABLE_FEATURE_HUMAN_READABLE 29#if ENABLE_FEATURE_HUMAN_READABLE
29# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K 30 unsigned long disp_hr;
30static unsigned long disp_hr = 1024;
31# else
32static unsigned long disp_hr = 512;
33# endif
34#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
35static unsigned disp_k = 1;
36#else 31#else
37static unsigned disp_k; /* bss inits to 0 */ 32 unsigned disp_k;
38#endif 33#endif
39 34
40static int max_print_depth = INT_MAX; 35 int max_print_depth;
41static nlink_t count_hardlinks = 1; 36 nlink_t count_hardlinks;
42 37
43static int status; 38 bool status;
44static int print_files; 39 bool one_file_system;
45static int slink_depth; 40 int print_files;
46static int du_depth; 41 int slink_depth;
47static int one_file_system; 42 int du_depth;
48static dev_t dir_dev; 43 dev_t dir_dev;
44};
45#define G (*(struct globals*)&bb_common_bufsiz1)
49 46
50 47
51static void print(long size, const char *const filename) 48static void print(unsigned long size, const char *filename)
52{ 49{
53 /* TODO - May not want to defer error checking here. */ 50 /* TODO - May not want to defer error checking here. */
54#if ENABLE_FEATURE_HUMAN_READABLE 51#if ENABLE_FEATURE_HUMAN_READABLE
55 printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), 52 printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr),
56 filename); 53 filename);
57#else 54#else
58 if (disp_k) { 55 if (G.disp_k) {
59 size++; 56 size++;
60 size >>= 1; 57 size >>= 1;
61 } 58 }
@@ -64,21 +61,21 @@ static void print(long size, const char *const filename)
64} 61}
65 62
66/* tiny recursive du */ 63/* tiny recursive du */
67static long du(const char *const filename) 64static unsigned long du(const char *filename)
68{ 65{
69 struct stat statbuf; 66 struct stat statbuf;
70 long sum; 67 unsigned long sum;
71 68
72 if (lstat(filename, &statbuf) != 0) { 69 if (lstat(filename, &statbuf) != 0) {
73 bb_perror_msg("%s", filename); 70 bb_perror_msg("%s", filename);
74 status = EXIT_FAILURE; 71 G.status = EXIT_FAILURE;
75 return 0; 72 return 0;
76 } 73 }
77 74
78 if (one_file_system) { 75 if (G.one_file_system) {
79 if (du_depth == 0) { 76 if (G.du_depth == 0) {
80 dir_dev = statbuf.st_dev; 77 G.dir_dev = statbuf.st_dev;
81 } else if (dir_dev != statbuf.st_dev) { 78 } else if (G.dir_dev != statbuf.st_dev) {
82 return 0; 79 return 0;
83 } 80 }
84 } 81 }
@@ -86,20 +83,20 @@ static long du(const char *const filename)
86 sum = statbuf.st_blocks; 83 sum = statbuf.st_blocks;
87 84
88 if (S_ISLNK(statbuf.st_mode)) { 85 if (S_ISLNK(statbuf.st_mode)) {
89 if (slink_depth > du_depth) { /* -H or -L */ 86 if (G.slink_depth > G.du_depth) { /* -H or -L */
90 if (stat(filename, &statbuf) != 0) { 87 if (stat(filename, &statbuf) != 0) {
91 bb_perror_msg("%s", filename); 88 bb_perror_msg("%s", filename);
92 status = EXIT_FAILURE; 89 G.status = EXIT_FAILURE;
93 return 0; 90 return 0;
94 } 91 }
95 sum = statbuf.st_blocks; 92 sum = statbuf.st_blocks;
96 if (slink_depth == 1) { 93 if (G.slink_depth == 1) {
97 slink_depth = INT_MAX; /* Convert -H to -L. */ 94 G.slink_depth = INT_MAX; /* Convert -H to -L. */
98 } 95 }
99 } 96 }
100 } 97 }
101 98
102 if (statbuf.st_nlink > count_hardlinks) { 99 if (statbuf.st_nlink > G.count_hardlinks) {
103 /* Add files/directories with links only once */ 100 /* Add files/directories with links only once */
104 if (is_in_ino_dev_hashtable(&statbuf)) { 101 if (is_in_ino_dev_hashtable(&statbuf)) {
105 return 0; 102 return 0;
@@ -114,7 +111,7 @@ static long du(const char *const filename)
114 111
115 dir = warn_opendir(filename); 112 dir = warn_opendir(filename);
116 if (!dir) { 113 if (!dir) {
117 status = EXIT_FAILURE; 114 G.status = EXIT_FAILURE;
118 return sum; 115 return sum;
119 } 116 }
120 117
@@ -128,16 +125,16 @@ static long du(const char *const filename)
128 newfile = concat_subpath_file(filename, name); 125 newfile = concat_subpath_file(filename, name);
129 if (newfile == NULL) 126 if (newfile == NULL)
130 continue; 127 continue;
131 ++du_depth; 128 ++G.du_depth;
132 sum += du(newfile); 129 sum += du(newfile);
133 --du_depth; 130 --G.du_depth;
134 free(newfile); 131 free(newfile);
135 } 132 }
136 closedir(dir); 133 closedir(dir);
137 } else if (du_depth > print_files) { 134 } else if (G.du_depth > G.print_files) {
138 return sum; 135 return sum;
139 } 136 }
140 if (du_depth <= max_print_depth) { 137 if (G.du_depth <= G.max_print_depth) {
141 print(sum, filename); 138 print(sum, filename);
142 } 139 }
143 return sum; 140 return sum;
@@ -146,21 +143,23 @@ static long du(const char *const filename)
146int du_main(int argc, char **argv); 143int du_main(int argc, char **argv);
147int du_main(int argc, char **argv) 144int du_main(int argc, char **argv)
148{ 145{
149 long total; 146 unsigned long total;
150 int slink_depth_save; 147 int slink_depth_save;
151 int print_final_total; 148 bool print_final_total;
152 char *smax_print_depth; 149 char *smax_print_depth;
153 unsigned opt; 150 unsigned opt;
154 151
155#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
156 if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
157#if ENABLE_FEATURE_HUMAN_READABLE 152#if ENABLE_FEATURE_HUMAN_READABLE
158 disp_hr = 512; 153 USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
154 SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
155 if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
156 G.disp_hr = 512;
159#else 157#else
160 disp_k = 0; 158 USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
161#endif 159 /* SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
162 }
163#endif 160#endif
161 G.max_print_depth = INT_MAX;
162 G.count_hardlinks = 1;
164 163
165 /* Note: SUSv3 specifies that -a and -s options cannot be used together 164 /* Note: SUSv3 specifies that -a and -s options cannot be used together
166 * in strictly conforming applications. However, it also says that some 165 * in strictly conforming applications. However, it also says that some
@@ -171,75 +170,76 @@ int du_main(int argc, char **argv)
171#if ENABLE_FEATURE_HUMAN_READABLE 170#if ENABLE_FEATURE_HUMAN_READABLE
172 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";
173 opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); 172 opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
173 argv += optind;
174 if (opt & (1 << 9)) { 174 if (opt & (1 << 9)) {
175 /* -h opt */ 175 /* -h opt */
176 disp_hr = 0; 176 G.disp_hr = 0;
177 } 177 }
178 if (opt & (1 << 10)) { 178 if (opt & (1 << 10)) {
179 /* -m opt */ 179 /* -m opt */
180 disp_hr = 1024*1024; 180 G.disp_hr = 1024*1024;
181 } 181 }
182 if (opt & (1 << 2)) { 182 if (opt & (1 << 2)) {
183 /* -k opt */ 183 /* -k opt */
184 disp_hr = 1024; 184 G.disp_hr = 1024;
185 } 185 }
186#else 186#else
187 opt_complementary = "H-L:L-H:s-d:d-s"; 187 opt_complementary = "H-L:L-H:s-d:d-s";
188 opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth); 188 opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth);
189 argv += optind;
189#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K 190#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
190 if (opt & (1 << 2)) { 191 if (opt & (1 << 2)) {
191 /* -k opt */ 192 /* -k opt */
192 disp_k = 1; 193 G.disp_k = 1;
193 } 194 }
194#endif 195#endif
195#endif 196#endif
196 if (opt & (1 << 0)) { 197 if (opt & (1 << 0)) {
197 /* -a opt */ 198 /* -a opt */
198 print_files = INT_MAX; 199 G.print_files = INT_MAX;
199 } 200 }
200 if (opt & (1 << 1)) { 201 if (opt & (1 << 1)) {
201 /* -H opt */ 202 /* -H opt */
202 slink_depth = 1; 203 G.slink_depth = 1;
203 } 204 }
204 if (opt & (1 << 3)) { 205 if (opt & (1 << 3)) {
205 /* -L opt */ 206 /* -L opt */
206 slink_depth = INT_MAX; 207 G.slink_depth = INT_MAX;
207 } 208 }
208 if (opt & (1 << 4)) { 209 if (opt & (1 << 4)) {
209 /* -s opt */ 210 /* -s opt */
210 max_print_depth = 0; 211 G.max_print_depth = 0;
211 } 212 }
212 one_file_system = opt & (1 << 5); /* -x opt */ 213 G.one_file_system = opt & (1 << 5); /* -x opt */
213 if (opt & (1 << 6)) { 214 if (opt & (1 << 6)) {
214 /* -d opt */ 215 /* -d opt */
215 max_print_depth = xatoi_u(smax_print_depth); 216 G.max_print_depth = xatoi_u(smax_print_depth);
216 } 217 }
217 if (opt & (1 << 7)) { 218 if (opt & (1 << 7)) {
218 /* -l opt */ 219 /* -l opt */
219 count_hardlinks = MAXINT(nlink_t); 220 G.count_hardlinks = MAXINT(nlink_t);
220 } 221 }
221 print_final_total = opt & (1 << 8); /* -c opt */ 222 print_final_total = opt & (1 << 8); /* -c opt */
222 223
223 /* go through remaining args (if any) */ 224 /* go through remaining args (if any) */
224 argv += optind; 225 if (!*argv) {
225 if (optind >= argc) {
226 *--argv = (char*)"."; 226 *--argv = (char*)".";
227 if (slink_depth == 1) { 227 if (G.slink_depth == 1) {
228 slink_depth = 0; 228 G.slink_depth = 0;
229 } 229 }
230 } 230 }
231 231
232 slink_depth_save = slink_depth; 232 slink_depth_save = G.slink_depth;
233 total = 0; 233 total = 0;
234 do { 234 do {
235 total += du(*argv); 235 total += du(*argv);
236 slink_depth = slink_depth_save; 236 G.slink_depth = slink_depth_save;
237 } while (*++argv); 237 } while (*++argv);
238
238 if (ENABLE_FEATURE_CLEAN_UP) 239 if (ENABLE_FEATURE_CLEAN_UP)
239 reset_ino_dev_hashtable(); 240 reset_ino_dev_hashtable();
240 if (print_final_total) { 241 if (print_final_total)
241 print(total, "total"); 242 print(total, "total");
242 }
243 243
244 fflush_stdout_and_exit(status); 244 fflush_stdout_and_exit(G.status);
245} 245}