diff options
author | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-12-10 07:40:08 +0000 |
---|---|---|
committer | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-12-10 07:40:08 +0000 |
commit | b788d4ef21183497186aa0c8b287a8072ee9688b (patch) | |
tree | 1b2eaa19e4688873ab2a5b754ae0b2c4b36c301f /du.c | |
parent | 23fb2f5dc016482219be1e68c5b22f193f2ef73e (diff) | |
download | busybox-w32-b788d4ef21183497186aa0c8b287a8072ee9688b.tar.gz busybox-w32-b788d4ef21183497186aa0c8b287a8072ee9688b.tar.bz2 busybox-w32-b788d4ef21183497186aa0c8b287a8072ee9688b.zip |
Fixed bug when dealing with files specified
on the command line that didn't exist.
git-svn-id: svn://busybox.net/trunk/busybox@195 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'du.c')
-rw-r--r-- | du.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -26,6 +26,7 @@ | |||
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 | #include <errno.h> | ||
29 | #if 0 | 30 | #if 0 |
30 | #include <unistd.h> | 31 | #include <unistd.h> |
31 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
@@ -49,7 +50,10 @@ du(char *filename) | |||
49 | struct stat statbuf; | 50 | struct stat statbuf; |
50 | size_t sum; | 51 | size_t sum; |
51 | 52 | ||
52 | if ((lstat(filename, &statbuf)) != 0) { return 0; } | 53 | if ((lstat(filename, &statbuf)) != 0) { |
54 | fprintf(stdout, "du: %s: %s\n", filename, strerror(errno)); | ||
55 | return 0; | ||
56 | } | ||
53 | sum = statbuf.st_blocks; | 57 | sum = statbuf.st_blocks; |
54 | 58 | ||
55 | if (S_ISDIR(statbuf.st_mode)) { | 59 | if (S_ISDIR(statbuf.st_mode)) { |
@@ -104,12 +108,14 @@ du_main(int argc, char **argv) | |||
104 | if (i >= argc) { | 108 | if (i >= argc) { |
105 | du("."); | 109 | du("."); |
106 | } else { | 110 | } else { |
111 | int sum; | ||
107 | for ( ; i < argc; i++) { | 112 | for ( ; i < argc; i++) { |
108 | printf("%-7d %s\n", du(argv[i]) >> 1, argv[i]); | 113 | sum = du(argv[i]) >> 1; |
114 | if (sum) printf("%-7d %s\n", du(argv[i]) >> 1, argv[i]); | ||
109 | } | 115 | } |
110 | } | 116 | } |
111 | 117 | ||
112 | exit(0); | 118 | exit(0); |
113 | } | 119 | } |
114 | 120 | ||
115 | /* $Id: du.c,v 1.3 1999/12/10 06:45:42 andersen Exp $ */ | 121 | /* $Id: du.c,v 1.4 1999/12/10 07:40:08 beppu Exp $ */ |