diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-02-21 17:27:17 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-02-21 17:27:17 +0000 |
commit | 42387e496463f6dbba168b5d36807b858f94fa96 (patch) | |
tree | 9958d84e73c0f497e80a110a56d7dca1b41d0565 /du.c | |
parent | 27fdd081efa060edf7467c43d76071f1c960d228 (diff) | |
download | busybox-w32-42387e496463f6dbba168b5d36807b858f94fa96.tar.gz busybox-w32-42387e496463f6dbba168b5d36807b858f94fa96.tar.bz2 busybox-w32-42387e496463f6dbba168b5d36807b858f94fa96.zip |
Forgot to add basename. More fixes to du from
Friedrich Vedder <fwv@myrtle.lahn.de>.
-Erik
Diffstat (limited to 'du.c')
-rw-r--r-- | du.c | 47 |
1 files changed, 39 insertions, 8 deletions
@@ -102,14 +102,30 @@ static void add_inode(const ino_t ino) | |||
102 | inode_hash_list[i] = inode; | 102 | inode_hash_list[i] = inode; |
103 | } | 103 | } |
104 | 104 | ||
105 | /* Clear inode hash list */ | ||
106 | static void reset_inode_list(void) | ||
107 | { | ||
108 | int i; | ||
109 | INODETYPE *inode; | ||
110 | |||
111 | for (i = 0; i < HASH_SIZE; i++) { | ||
112 | while (inode_hash_list[i] != NULL) { | ||
113 | inode = inode_hash_list[i]->next; | ||
114 | free(inode_hash_list[i]); | ||
115 | inode_hash_list[i] = inode; | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
105 | /* tiny recursive du */ | 120 | /* tiny recursive du */ |
106 | static long du(char *filename) | 121 | static long du(char *filename) |
107 | { | 122 | { |
108 | struct stat statbuf; | 123 | struct stat statbuf; |
109 | long sum; | 124 | long sum; |
125 | int len; | ||
110 | 126 | ||
111 | if ((lstat(filename, &statbuf)) != 0) { | 127 | if ((lstat(filename, &statbuf)) != 0) { |
112 | fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); | 128 | printf("du: %s: %s\n", filename, strerror(errno)); |
113 | return 0; | 129 | return 0; |
114 | } | 130 | } |
115 | 131 | ||
@@ -118,7 +134,9 @@ static long du(char *filename) | |||
118 | 134 | ||
119 | /* Don't add in stuff pointed to by symbolic links */ | 135 | /* Don't add in stuff pointed to by symbolic links */ |
120 | if (S_ISLNK(statbuf.st_mode)) { | 136 | if (S_ISLNK(statbuf.st_mode)) { |
121 | return 0; | 137 | sum = 0L; |
138 | if (du_depth == 1) | ||
139 | print(sum, filename); | ||
122 | } | 140 | } |
123 | if (S_ISDIR(statbuf.st_mode)) { | 141 | if (S_ISDIR(statbuf.st_mode)) { |
124 | DIR *dir; | 142 | DIR *dir; |
@@ -126,8 +144,14 @@ static long du(char *filename) | |||
126 | 144 | ||
127 | dir = opendir(filename); | 145 | dir = opendir(filename); |
128 | if (!dir) { | 146 | if (!dir) { |
147 | du_depth--; | ||
129 | return 0; | 148 | return 0; |
130 | } | 149 | } |
150 | |||
151 | len = strlen(filename); | ||
152 | if (filename[len - 1] == '/') | ||
153 | filename[--len] = '\0'; | ||
154 | |||
131 | while ((entry = readdir(dir))) { | 155 | while ((entry = readdir(dir))) { |
132 | char newfile[PATH_MAX + 1]; | 156 | char newfile[PATH_MAX + 1]; |
133 | char *name = entry->d_name; | 157 | char *name = entry->d_name; |
@@ -137,8 +161,9 @@ static long du(char *filename) | |||
137 | continue; | 161 | continue; |
138 | } | 162 | } |
139 | 163 | ||
140 | if (strlen(filename) + strlen(name) + 1 > PATH_MAX) { | 164 | if (len + strlen(name) + 1 > PATH_MAX) { |
141 | fprintf(stderr, name_too_long, "du"); | 165 | fprintf(stderr, name_too_long, "du"); |
166 | du_depth--; | ||
142 | return 0; | 167 | return 0; |
143 | } | 168 | } |
144 | sprintf(newfile, "%s/%s", filename, name); | 169 | sprintf(newfile, "%s/%s", filename, name); |
@@ -150,9 +175,14 @@ static long du(char *filename) | |||
150 | } | 175 | } |
151 | else if (statbuf.st_nlink > 1 && !count_hardlinks) { | 176 | else if (statbuf.st_nlink > 1 && !count_hardlinks) { |
152 | /* Add files with hard links only once */ | 177 | /* Add files with hard links only once */ |
153 | if (is_in_list(statbuf.st_ino)) | 178 | if (is_in_list(statbuf.st_ino)) { |
154 | return 0; | 179 | sum = 0L; |
155 | add_inode(statbuf.st_ino); | 180 | if (du_depth == 1) |
181 | print(sum, filename); | ||
182 | } | ||
183 | else { | ||
184 | add_inode(statbuf.st_ino); | ||
185 | } | ||
156 | } | 186 | } |
157 | du_depth--; | 187 | du_depth--; |
158 | return sum; | 188 | return sum; |
@@ -198,13 +228,14 @@ int du_main(int argc, char **argv) | |||
198 | 228 | ||
199 | for (; i < argc; i++) { | 229 | for (; i < argc; i++) { |
200 | sum = du(argv[i]); | 230 | sum = du(argv[i]); |
201 | if ((sum) && (isDirectory(argv[i], FALSE, NULL))) { | 231 | if (sum && isDirectory(argv[i], FALSE, NULL)) { |
202 | print_normal(sum, argv[i]); | 232 | print_normal(sum, argv[i]); |
203 | } | 233 | } |
234 | reset_inode_list(); | ||
204 | } | 235 | } |
205 | } | 236 | } |
206 | 237 | ||
207 | exit(0); | 238 | exit(0); |
208 | } | 239 | } |
209 | 240 | ||
210 | /* $Id: du.c,v 1.14 2000/02/19 18:16:49 erik Exp $ */ | 241 | /* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */ |