diff options
author | Jim Meyering <jim@meyering.net> | 1994-01-29 18:31:36 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1994-01-29 18:31:36 +0000 |
commit | 200b442ee4e8e0a6cf58bff092289051ae803d3d (patch) | |
tree | 488706db4d70e94e5e69897b7e19701e24f6d0e7 /src/du.c | |
parent | ad824045640d1cb2315cbfd8808acace5c614785 (diff) | |
download | coreutils-200b442ee4e8e0a6cf58bff092289051ae803d3d.tar.xz |
.
Diffstat (limited to 'src/du.c')
-rw-r--r-- | src/du.c | 24 |
1 files changed, 8 insertions, 16 deletions
@@ -173,6 +173,9 @@ static int show_help; /* If non-zero, print the version on standard output and exit. */ static int show_version; +/* Grand total size of all args. */ +static long tot_size = 0L; + static struct option const long_options[] = { {"all", no_argument, &opt_all, 1}, @@ -229,6 +232,7 @@ main (argc, argv) char *argv[]; { int c; + char *cwd_only[] = {".", NULL}; program_name = argv[0]; xstat = lstat; @@ -304,20 +308,7 @@ main (argc, argv) str_init (&path, INITIAL_PATH_SIZE); - if (optind == argc) - { - str_copyc (path, "."); - - /* Initialize the hash structure for inode numbers. */ - hash_reset (); - - /* Get the size of the current directory only. */ - count_entry (".", 1, 0); - } - else - { - du_files (argv + optind); - } + du_files (optind == argc ? cwd_only : argv + optind); exit (exit_status); } @@ -332,7 +323,6 @@ du_files (files) char *wd; ino_t initial_ino; /* Initial directory's inode. */ dev_t initial_dev; /* Initial directory's device. */ - long tot_size = 0L; /* Grand total size of all args. */ int i; /* Index in FILES. */ wd = xgetcwd (); @@ -369,7 +359,7 @@ du_files (files) if (!opt_combined_arguments) hash_reset (); - tot_size += count_entry (arg, 1, 0); + count_entry (arg, 1, 0); /* chdir if `count_entry' has changed the working directory. */ if (stat (".", &stat_buf)) @@ -421,6 +411,8 @@ count_entry (ent, top, last_dev) else size = ST_NBLOCKS (stat_buf); + tot_size += size; + if (S_ISDIR (stat_buf.st_mode)) { unsigned pathlen; |