Brain bug.
[dus.git] / dus.c
diff --git a/dus.c b/dus.c
index 9330ebd..ac1a7d3 100644 (file)
--- a/dus.c
+++ b/dus.c
@@ -3,7 +3,7 @@
  *  dus is a simple utility to display the files and directories
  *  according to their total disk occupancy.
  *
- *  Copyright (c) 2010 Francois Fleuret
+ *  Copyright (c) 2010, 2011 Francois Fleuret
  *  Written by Francois Fleuret <francois@fleuret.org>
  *
  *  This file is part of dus.
@@ -24,7 +24,7 @@
 
 #define VERSION_NUMBER "1.3"
 
-#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -66,9 +66,9 @@ size_sum_t size_min = -1; /* -1 means no minimum size, otherwise lower
                               bound on the size to display a
                               file/dir */
 
-int ignore_protected_files = 0; /* Should we simply ignore files or
-                                   directories which are protected
-                                   ? */
+int dont_exit_on_protected_files = 0; /* Should we go on when we meet
+                                         files or directories which
+                                         are protected ? */
 
 /********************************************************************/
 
@@ -105,10 +105,10 @@ size_sum_t entry_size(const char *name, int *isdir) {
   if(isdir) { *isdir = 0; }
 
   if(lstat(name, &dummy) != 0) {
-    if(!(errno == EACCES && ignore_protected_files)) {
-      fprintf(stderr,
-              "dus: Can not stat %s: %s\n",
-              name, strerror(errno));
+    fprintf(stderr,
+            "dus: Can not stat %s: %s\n",
+            name, strerror(errno));
+    if(!(errno == EACCES && dont_exit_on_protected_files)) {
       exit(EXIT_FAILURE);
     } else {
       return 0;
@@ -131,10 +131,10 @@ size_sum_t entry_size(const char *name, int *isdir) {
       }
       closedir(dir);
     } else {
-      if(!(errno == EACCES && ignore_protected_files)) {
-        fprintf(stderr,
-                "dus: Can not open directory %s: %s\n",
-                name, strerror(errno));
+      fprintf(stderr,
+              "dus: Can not open directory %s: %s\n",
+              name, strerror(errno));
+      if(!(errno == EACCES && dont_exit_on_protected_files)) {
         exit(EXIT_FAILURE);
       }
     }
@@ -295,25 +295,25 @@ void fancy_print(char *buffer, size_t buffer_size,
   if(size < 1024) {
     snprintf(buffer,
              buffer_size,
-             "% 8d -- %s\n",
+             "% 8d %s\n",
              ((int) size),
              filename);
   } else if(size < 1024 * 1024) {
     snprintf(buffer,
              buffer_size,
-             "% 7.1fK -- %s\n",
+             "% 7.1fK %s\n",
              ((double) (size))/(1024.0),
              filename);
   } else if(size < 1024 * 1024 * 1024) {
     snprintf(buffer,
              buffer_size,
-             "% 7.1fM -- %s\n",
+             "% 7.1fM %s\n",
              ((double) (size))/(1024.0 * 1024),
              filename);
   } else {
     snprintf(buffer,
              buffer_size,
-             "% 7.1fG -- %s\n",
+             "% 7.1fG %s\n",
              ((double) (size))/(1024.0 * 1024.0 * 1024.0),
              filename);
   }
@@ -404,8 +404,8 @@ void usage(FILE *out) {
   fprintf(out, "   -h, --help                 show this help.\n");
   fprintf(out, "   -v, --version              prints the version number and exit\n");
   fprintf(out, "   -d, --ignore-dots          ignore files and directories starting with a '.'\n");
-  fprintf(out, "   -i, --ignore-protected     ignore files and directories for which we do not\n");
-  fprintf(out, "                              have permission\n");
+  fprintf(out, "   -i, --ignore-protected     do not exit when visiting files and directories\n");
+  fprintf(out, "                              for which we do not have permission\n");
   fprintf(out, "   -f, --fancy                display size with float values and K, M and G\n");
   fprintf(out, "                              units.\n");
   fprintf(out, "   -r, --reverse-order        reverse the sorting order.\n");
@@ -463,7 +463,7 @@ int main(int argc, char **argv) {
       break;
 
     case 'i':
-      ignore_protected_files = 1;
+      dont_exit_on_protected_files = 1;
       break;
 
     case 'f':