- do {
- if (argc > 1) {
- pid = fork();
- if (pid == -1) {
- fprintf(stderr, "No more processes.\n");
- exit(1);
- }
- if (pid != 0)
- wait((int *)0);
- }
- if (argc == 1 || pid == 0) {
- (void) strcpy(path, *argv);
- (void) strcpy(name, *argv);
- if (np = rindex(name, '/')) {
- *np++ = '\0';
- if (chdir(*name ? name : "/") < 0) {
- perror(*name ? name : "/");
- exit(1);
- }
- } else
- np = path;
- blocks = descend(path, *np ? np : ".");
- if (sflg)
- printf("%ld\t%s\n", kb(blocks), path);
- if (argc > 1)
- exit(1);
+
+ (void)getbsize("du", ¬used, &blocksize);
+ blocksize /= 512;
+
+ if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
+ err(1, "");
+
+ while (p = fts_read(fts))
+ switch(p->fts_info) {
+ case FTS_D:
+ break;
+ case FTS_DP:
+ p->fts_parent->fts_number +=
+ p->fts_number += p->fts_statp->st_blocks;
+ /*
+ * If listing each directory, or not listing files
+ * or directories and this is post-order of the
+ * root of a traversal, display the total.
+ */
+ if (listdirs || !listfiles && !p->fts_level)
+ (void)printf("%ld\t%s\n",
+ howmany(p->fts_number, blocksize),
+ p->fts_path);
+ break;
+ case FTS_DNR:
+ case FTS_ERR:
+ case FTS_NS:
+ warn("%s", p->fts_path);
+ break;
+ default:
+ if (p->fts_statp->st_nlink > 1 && linkchk(p))
+ break;
+ /*
+ * If listing each file, or a non-directory file was
+ * the root of a traversal, display the total.
+ */
+ if (listfiles || !p->fts_level)
+ (void)printf("%qd\t%s\n",
+ howmany(p->fts_statp->st_blocks, blocksize),
+ p->fts_path);
+ p->fts_parent->fts_number += p->fts_statp->st_blocks;