From: Francois Fleuret Date: Mon, 18 Apr 2011 06:25:08 +0000 (+0200) Subject: Keep the stderr messages on file access errors even with the -i option. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=c28dd144254def45a3cbb87c7908cc5f7209ecdb;p=dus.git Keep the stderr messages on file access errors even with the -i option. --- diff --git a/dus.1 b/dus.1 index e791861..01b5cc1 100644 --- a/dus.1 +++ b/dus.1 @@ -33,7 +33,7 @@ print the version number and exit ignore files and directories whose name starts with a dot .TP \fB-i\fR, \fB--ignore-protected\fR -ignore files and directories for which we do not have permission +do not exit when trying to access files and directories for which we do not have permission .TP \fB-f\fR, \fB--fancy\fR display floating point size with K, M and G units diff --git a/dus.c b/dus.c index a7e3908..6de022a 100644 --- a/dus.c +++ b/dus.c @@ -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); } } @@ -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':