diff options
author | John Beppu <beppu@lbox.org> | 1999-12-10 06:15:27 +0000 |
---|---|---|
committer | John Beppu <beppu@lbox.org> | 1999-12-10 06:15:27 +0000 |
commit | 14c82b64c9e94fba678f439e0fd8236ea6a6ee1e (patch) | |
tree | ca6951b2eb89f8d13188e1b82e1ec4de8636c36c /du.c | |
parent | 2ad2afd05c6c848cbdc7d745be4edc22dcd13b8e (diff) | |
download | busybox-w32-14c82b64c9e94fba678f439e0fd8236ea6a6ee1e.tar.gz busybox-w32-14c82b64c9e94fba678f439e0fd8236ea6a6ee1e.tar.bz2 busybox-w32-14c82b64c9e94fba678f439e0fd8236ea6a6ee1e.zip |
Fleshed out du_main().
I'm not sure which options to support.
Diffstat (limited to 'du.c')
-rw-r--r-- | du.c | 44 |
1 files changed, 38 insertions, 6 deletions
@@ -26,11 +26,13 @@ | |||
26 | #include <fcntl.h> | 26 | #include <fcntl.h> |
27 | #include <dirent.h> | 27 | #include <dirent.h> |
28 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | /* | 29 | #if 0 |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | */ | 32 | #endif |
33 | 33 | ||
34 | static const char du_usage[] = | ||
35 | "Usage: du [OPTION]... [FILE]...\n"; | ||
34 | 36 | ||
35 | typedef void (Display)(size_t, char *); | 37 | typedef void (Display)(size_t, char *); |
36 | 38 | ||
@@ -42,7 +44,7 @@ print(size_t size, char *filename) | |||
42 | 44 | ||
43 | /* tiny recursive du */ | 45 | /* tiny recursive du */ |
44 | static size_t | 46 | static size_t |
45 | size(char *filename) | 47 | du(char *filename) |
46 | { | 48 | { |
47 | struct stat statbuf; | 49 | struct stat statbuf; |
48 | size_t sum; | 50 | size_t sum; |
@@ -65,7 +67,7 @@ size(char *filename) | |||
65 | { continue; } | 67 | { continue; } |
66 | 68 | ||
67 | sprintf(newfile, "%s/%s", filename, name); | 69 | sprintf(newfile, "%s/%s", filename, name); |
68 | sum += size(newfile); | 70 | sum += du(newfile); |
69 | } | 71 | } |
70 | closedir(dir); | 72 | closedir(dir); |
71 | print(sum, filename); | 73 | print(sum, filename); |
@@ -76,8 +78,38 @@ size(char *filename) | |||
76 | int | 78 | int |
77 | du_main(int argc, char **argv) | 79 | du_main(int argc, char **argv) |
78 | { | 80 | { |
79 | /* I'll fill main() in shortly */ | 81 | int i; |
80 | size("."); | 82 | char opt; |
83 | |||
84 | /* parse argv[] */ | ||
85 | for (i = 1; i < argc; i++) { | ||
86 | if (argv[i][0] == '-') { | ||
87 | opt = argv[i][1]; | ||
88 | switch (opt) { | ||
89 | case 's': | ||
90 | break; | ||
91 | case 'h': | ||
92 | usage(du_usage); | ||
93 | break; | ||
94 | default: | ||
95 | fprintf(stderr, "du: invalid option -- %c\n", opt); | ||
96 | usage(du_usage); | ||
97 | } | ||
98 | } else { | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /* go through remaining args (if any) */ | ||
104 | if (i >= argc) { | ||
105 | du("."); | ||
106 | } else { | ||
107 | for ( ; i < argc; i++) { | ||
108 | printf("%-7d %s\n", du(argv[i]) >> 1, argv[i]); | ||
109 | } | ||
110 | } | ||
111 | |||
81 | exit(0); | 112 | exit(0); |
82 | } | 113 | } |
83 | 114 | ||
115 | /* $Id: du.c,v 1.2 1999/12/10 06:15:27 beppu Exp $ */ | ||