diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-02-07 05:29:42 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-02-07 05:29:42 +0000 |
| commit | fac10d7c59f7db0facd5fb94de273310b9ec86e6 (patch) | |
| tree | dccf8f905fc5807239883da9fca6597037d487fc /coreutils/du.c | |
| parent | 50bc101b7d6e847a9a0621ca3eb28c7117d095e5 (diff) | |
| download | busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.gz busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.bz2 busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.zip | |
A few minor updates. ;-)
Seriously though, read the Changelog for busybox 0.42,
which this is about to become...
-Erik
Diffstat (limited to 'coreutils/du.c')
| -rw-r--r-- | coreutils/du.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/coreutils/du.c b/coreutils/du.c index 79b553643..e2cf3f7c0 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
| @@ -22,17 +22,18 @@ | |||
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #include "internal.h" | 24 | #include "internal.h" |
| 25 | #define BB_DECLARE_EXTERN | ||
| 26 | #define bb_need_name_too_long | ||
| 27 | #include "messages.c" | ||
| 28 | |||
| 25 | #include <sys/types.h> | 29 | #include <sys/types.h> |
| 26 | #include <fcntl.h> | 30 | #include <fcntl.h> |
| 27 | #include <dirent.h> | 31 | #include <dirent.h> |
| 28 | #include <stdio.h> | 32 | #include <stdio.h> |
| 29 | #include <errno.h> | 33 | #include <errno.h> |
| 30 | #if 0 | 34 | #include <sys/param.h> /* for PATH_MAX */ |
| 31 | #include <unistd.h> | ||
| 32 | #include <sys/stat.h> | ||
| 33 | #endif | ||
| 34 | 35 | ||
| 35 | typedef void (Display)(size_t, char *); | 36 | typedef void (Display)(long, char *); |
| 36 | 37 | ||
| 37 | static const char du_usage[] = | 38 | static const char du_usage[] = |
| 38 | "du [OPTION]... [FILE]...\n\n" | 39 | "du [OPTION]... [FILE]...\n\n" |
| @@ -44,13 +45,13 @@ static int du_depth = 0; | |||
| 44 | static Display *print; | 45 | static Display *print; |
| 45 | 46 | ||
| 46 | static void | 47 | static void |
| 47 | print_normal(size_t size, char *filename) | 48 | print_normal(long size, char *filename) |
| 48 | { | 49 | { |
| 49 | fprintf(stdout, "%-7d %s\n", (size >> 1), filename); | 50 | fprintf(stdout, "%-7ld %s\n", size, filename); |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | static void | 53 | static void |
| 53 | print_summary(size_t size, char *filename) | 54 | print_summary(long size, char *filename) |
| 54 | { | 55 | { |
| 55 | if (du_depth == 1) { | 56 | if (du_depth == 1) { |
| 56 | print_normal(size, filename); | 57 | print_normal(size, filename); |
| @@ -59,11 +60,11 @@ print_summary(size_t size, char *filename) | |||
| 59 | 60 | ||
| 60 | 61 | ||
| 61 | /* tiny recursive du */ | 62 | /* tiny recursive du */ |
| 62 | static size_t | 63 | static long |
| 63 | du(char *filename) | 64 | du(char *filename) |
| 64 | { | 65 | { |
| 65 | struct stat statbuf; | 66 | struct stat statbuf; |
| 66 | size_t sum; | 67 | long sum; |
| 67 | 68 | ||
| 68 | if ((lstat(filename, &statbuf)) != 0) { | 69 | if ((lstat(filename, &statbuf)) != 0) { |
| 69 | fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); | 70 | fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); |
| @@ -80,14 +81,19 @@ du(char *filename) | |||
| 80 | dir = opendir(filename); | 81 | dir = opendir(filename); |
| 81 | if (!dir) { return 0; } | 82 | if (!dir) { return 0; } |
| 82 | while ((entry = readdir(dir))) { | 83 | while ((entry = readdir(dir))) { |
| 83 | char newfile[512]; | 84 | char newfile[PATH_MAX + 1]; |
| 84 | char *name = entry->d_name; | 85 | char *name = entry->d_name; |
| 85 | 86 | ||
| 86 | if ( (strcmp(name, "..") == 0) | 87 | if ( (strcmp(name, "..") == 0) |
| 87 | || (strcmp(name, ".") == 0)) | 88 | || (strcmp(name, ".") == 0)) |
| 88 | { continue; } | 89 | { continue; } |
| 89 | 90 | ||
| 91 | if (strlen(filename) + strlen(name) + 1 > PATH_MAX) { | ||
| 92 | fprintf(stderr, name_too_long, "du"); | ||
| 93 | return 0; | ||
| 94 | } | ||
| 90 | sprintf(newfile, "%s/%s", filename, name); | 95 | sprintf(newfile, "%s/%s", filename, name); |
| 96 | |||
| 91 | sum += du(newfile); | 97 | sum += du(newfile); |
| 92 | } | 98 | } |
| 93 | closedir(dir); | 99 | closedir(dir); |
| @@ -130,14 +136,14 @@ du_main(int argc, char **argv) | |||
| 130 | if (i >= argc) { | 136 | if (i >= argc) { |
| 131 | du("."); | 137 | du("."); |
| 132 | } else { | 138 | } else { |
| 133 | int sum; | 139 | long sum; |
| 134 | for ( ; i < argc; i++) { | 140 | for ( ; i < argc; i++) { |
| 135 | sum = du(argv[i]); | 141 | sum = du(argv[i]); |
| 136 | if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); } | 142 | if ((sum) && (isDirectory(argv[i], FALSE))) { print_normal(sum, argv[i]); } |
| 137 | } | 143 | } |
| 138 | } | 144 | } |
| 139 | 145 | ||
| 140 | exit(0); | 146 | exit(0); |
| 141 | } | 147 | } |
| 142 | 148 | ||
| 143 | /* $Id: du.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */ | 149 | /* $Id: du.c,v 1.10 2000/02/07 05:29:42 erik Exp $ */ |
