1
0
mirror of git://git.suckless.org/sbase synced 2024-12-25 00:12:42 +00:00

Fix indentation in du(1)

This commit is contained in:
sin 2013-10-17 18:03:01 +01:00
parent 9e321b69d2
commit a6e5696cbd

64
du.c
View File

@ -109,38 +109,42 @@ du(const char *path)
eprintf("stat: %s:", path); eprintf("stat: %s:", path);
n = 512 * st.st_blocks / blksize; n = 512 * st.st_blocks / blksize;
if (S_ISDIR(st.st_mode)) { if (!S_ISDIR(st.st_mode))
dp = opendir(path); goto done;
if (!dp) {
fprintf(stderr, "opendir: %s: %s\n", path, dp = opendir(path);
strerror(errno)); if (!dp) {
} else { fprintf(stderr, "opendir: %s: %s\n", path,
cwd = push(path); strerror(errno));
while ((dent = readdir(dp))) { goto done;
if (strcmp(dent->d_name, ".") == 0 ||
strcmp(dent->d_name, "..") == 0)
continue;
if (lstat(dent->d_name, &st) < 0)
eprintf("stat: %s:", dent->d_name);
if (S_ISDIR(st.st_mode)) {
n += du(dent->d_name);
} else {
m = 512 * st.st_blocks / blksize;
n += m;
if (aflag && !sflag) {
if (S_ISLNK(st.st_mode))
snprintf(file, sizeof(file), "%s/%s", cwd, dent->d_name);
else
realpath(dent->d_name, file);
print(m, file);
}
}
}
pop(cwd);
closedir(dp);
}
} }
cwd = push(path);
while ((dent = readdir(dp))) {
if (strcmp(dent->d_name, ".") == 0 ||
strcmp(dent->d_name, "..") == 0)
continue;
if (lstat(dent->d_name, &st) < 0)
eprintf("stat: %s:", dent->d_name);
if (S_ISDIR(st.st_mode)) {
n += du(dent->d_name);
continue;
}
m = 512 * st.st_blocks / blksize;
n += m;
if (aflag && !sflag) {
if (S_ISLNK(st.st_mode))
snprintf(file, sizeof(file), "%s/%s",
cwd, dent->d_name);
else
realpath(dent->d_name, file);
print(m, file);
}
}
pop(cwd);
closedir(dp);
done:
if (!sflag) if (!sflag)
print(n, realpath(path, file)); print(n, realpath(path, file));
return n; return n;