[hackers] [sbase] Fix indentation in du(1) || sin

From: <git_AT_suckless.org>
Date: Thu, 17 Oct 2013 19:11:30 +0200

commit a6e5696cbda5a29f94a98563a8fb63987b94edde
Author: sin <sin_AT_2f30.org>
Date: Thu Oct 17 18:03:01 2013 +0100

    Fix indentation in du(1)

diff --git a/du.c b/du.c
index b83aba9..44281fd 100644
--- a/du.c
+++ b/du.c
_AT_@ -109,38 +109,42 @@ du(const char *path)
                 eprintf("stat: %s:", path);
         n = 512 * st.st_blocks / blksize;
 
- if (S_ISDIR(st.st_mode)) {
- dp = opendir(path);
- if (!dp) {
- fprintf(stderr, "opendir: %s: %s
", path,
- strerror(errno));
- } else {
- 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);
- } 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);
+ if (!S_ISDIR(st.st_mode))
+ goto done;
+
+ dp = opendir(path);
+ if (!dp) {
+ fprintf(stderr, "opendir: %s: %s
", path,
+ strerror(errno));
+ goto done;
+ }
+
+ 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)
                 print(n, realpath(path, file));
         return n;
Received on Thu Oct 17 2013 - 19:11:30 CEST

This archive was generated by hypermail 2.3.0 : Thu Oct 17 2013 - 19:12:17 CEST