X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=du.c;h=408ad994cc626c41f3be8e458c14945ae5c4addf;hb=8c725e624a6fa97175f48e0fc34b37403e3b8613;hp=874538015407dcb2e13ee7f58e9a6614b1b3c740;hpb=61677feff7f549a48267c2c0c50a7420de6e2599;p=oweals%2Fbusybox.git diff --git a/du.c b/du.c index 874538015..408ad994c 100644 --- a/du.c +++ b/du.c @@ -22,7 +22,7 @@ * */ -#include "internal.h" +#include "busybox.h" #define BB_DECLARE_EXTERN #define bb_need_name_too_long #include "messages.c" @@ -32,18 +32,9 @@ #include #include #include -#include /* for PATH_MAX */ typedef void (Display) (long, char *); -static const char du_usage[] = - "du [OPTION]... [FILE]...\n\n" - "Summarize disk space used for each FILE and/or directory.\n" - "Disk space is printed in units of 1024 bytes.\n\n" - "Options:\n" - "\t-l\tcount sizes many times if hard linked\n" - "\t-s\tdisplay only a total for each argument\n"; - static int du_depth = 0; static int count_hardlinks = 0; @@ -97,7 +88,7 @@ static long du(char *filename) filename[--len] = '\0'; while ((entry = readdir(dir))) { - char newfile[PATH_MAX + 1]; + char newfile[BUFSIZ + 1]; char *name = entry->d_name; if ((strcmp(name, "..") == 0) @@ -105,8 +96,8 @@ static long du(char *filename) continue; } - if (len + strlen(name) + 1 > PATH_MAX) { - fprintf(stderr, name_too_long, "du"); + if (len + strlen(name) + 1 > BUFSIZ) { + errorMsg(name_too_long); du_depth--; return 0; } @@ -135,42 +126,32 @@ static long du(char *filename) int du_main(int argc, char **argv) { int i; - char opt; + int c; /* default behaviour */ print = print_normal; /* parse argv[] */ - for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') { - opt = argv[i][1]; - switch (opt) { + while ((c = getopt(argc, argv, "sl")) != EOF) { + switch (c) { case 's': - print = print_summary; - break; + print = print_summary; + break; case 'l': - count_hardlinks = 1; - break; - case 'h': - case '-': - usage(du_usage); - break; + count_hardlinks = 1; + break; default: - fprintf(stderr, "du: invalid option -- %c\n", opt); - usage(du_usage); + usage(du_usage); } - } else { - break; - } } /* go through remaining args (if any) */ - if (i >= argc) { + if (optind >= argc) { du("."); } else { long sum; - for (; i < argc; i++) { + for (i=optind; i < argc; i++) { sum = du(argv[i]); if (sum && isDirectory(argv[i], FALSE, NULL)) { print_normal(sum, argv[i]); @@ -179,10 +160,10 @@ int du_main(int argc, char **argv) } } - exit(0); + return(0); } -/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */ +/* $Id: du.c,v 1.25 2000/09/25 21:45:57 andersen Exp $ */ /* Local Variables: c-file-style: "linux"