* 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.
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 ? */
/********************************************************************/
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;
}
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);
}
}
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);
}
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");
break;
case 'i':
- ignore_protected_files = 1;
+ dont_exit_on_protected_files = 1;
break;
case 'f':