projects
/
dus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Now exit on min size syntax error, and added 'dus: ' to error messages.
[dus.git]
/
dus.c
diff --git
a/dus.c
b/dus.c
index
03bd980
..
6557c7f
100644
(file)
--- a/
dus.c
+++ b/
dus.c
@@
-73,7
+73,7
@@
size_sum_t size_min = -1; /* -1 means no minimum size, otherwise lower
void *safe_malloc(size_t n) {
void *p = malloc(n);
if (!p && n != 0) {
void *safe_malloc(size_t n) {
void *p = malloc(n);
if (!p && n != 0) {
- fprintf(stderr, "Can not allocate memory: %s\n", strerror(errno));
+ fprintf(stderr, "
dus:
Can not allocate memory: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
return p;
exit(EXIT_FAILURE);
}
return p;
@@
-98,7
+98,7
@@
size_sum_t entry_size(const char *name) {
result = 0;
if(lstat(name, &dummy) != 0) {
result = 0;
if(lstat(name, &dummy) != 0) {
- fprintf(stderr, "Can not stat %s: %s\n", name, strerror(errno));
+ fprintf(stderr, "
dus:
Can not stat %s: %s\n", name, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
@@
-117,7
+117,7
@@
size_sum_t entry_size(const char *name) {
}
closedir(dir);
} else {
}
closedir(dir);
} else {
- fprintf(stderr, "Can not open directory %s: %s\n", name, strerror(errno));
+ fprintf(stderr, "
dus:
Can not open directory %s: %s\n", name, strerror(errno));
exit(EXIT_FAILURE);
}
} else if(S_ISREG(dummy.st_mode)) {
exit(EXIT_FAILURE);
}
} else if(S_ISREG(dummy.st_mode)) {
@@
-136,6
+136,9
@@
size_sum_t atoss(const char *string) {
for(c = string; *c; c++) {
if(*c >= '0' && *c <= '9') {
partial_total = 10 * partial_total + ((int) (*c - '0'));
for(c = string; *c; c++) {
if(*c >= '0' && *c <= '9') {
partial_total = 10 * partial_total + ((int) (*c - '0'));
+ } else if(*c == 'B' || *c == 'b') {
+ total += partial_total;
+ partial_total = 0;
} else if(*c == 'K' || *c == 'k') {
total += partial_total * 1024;
partial_total = 0;
} else if(*c == 'K' || *c == 'k') {
total += partial_total * 1024;
partial_total = 0;
@@
-146,9
+149,13
@@
size_sum_t atoss(const char *string) {
total += partial_total * 1024 * 1024 * 1024;
partial_total = 0;
} else {
total += partial_total * 1024 * 1024 * 1024;
partial_total = 0;
} else {
- fprintf(stderr, "Syntax error in %s\n", string);
+ fprintf(stderr, "dus: Syntax error in size specification `%s'\n", string);
+ exit(EXIT_FAILURE);
}
}
}
}
+
+ total += partial_total;
+
return total;
}
return total;
}
@@
-183,7
+190,7
@@
struct entry_node *push_dir_content(char *name, struct entry_node *head) {
}
closedir(dir);
} else {
}
closedir(dir);
} else {
- fprintf(stderr, "Can not open directory %s: %s\n", name, strerror(errno));
+ fprintf(stderr, "
dus:
Can not open directory %s: %s\n", name, strerror(errno));
exit (EXIT_FAILURE);
}
return head;
exit (EXIT_FAILURE);
}
return head;
@@
-233,7
+240,7
@@
void raw_print(char *buffer, size_t buffer_size,
b = buffer;
do {
if(b >= buffer + buffer_size) {
b = buffer;
do {
if(b >= buffer + buffer_size) {
- fprintf(stderr, "Buffer overflow in raw_print (hu?!).\n");
+ fprintf(stderr, "
dus:
Buffer overflow in raw_print (hu?!).\n");
exit(EXIT_FAILURE);
}
*(b++) = size%10 + '0';
exit(EXIT_FAILURE);
}
*(b++) = size%10 + '0';
@@
-258,25
+265,25
@@
void fancy_print(char *buffer, size_t buffer_size,
if(size < 1024) {
snprintf(buffer,
buffer_size,
if(size < 1024) {
snprintf(buffer,
buffer_size,
- "%
7
d -- %s\n",
+ "%
8
d -- %s\n",
((int) size),
filename);
} else if(size < 1024 * 1024) {
snprintf(buffer,
buffer_size,
((int) size),
filename);
} else if(size < 1024 * 1024) {
snprintf(buffer,
buffer_size,
- "%
6
.1fK -- %s\n",
+ "%
7
.1fK -- %s\n",
((double) (size))/(1024.0),
filename);
} else if(size < 1024 * 1024 * 1024) {
snprintf(buffer,
buffer_size,
((double) (size))/(1024.0),
filename);
} else if(size < 1024 * 1024 * 1024) {
snprintf(buffer,
buffer_size,
- "%
6
.1fM -- %s\n",
+ "%
7
.1fM -- %s\n",
((double) (size))/(1024.0 * 1024),
filename);
} else {
snprintf(buffer,
buffer_size,
((double) (size))/(1024.0 * 1024),
filename);
} else {
snprintf(buffer,
buffer_size,
- "%
6
.1fG -- %s\n",
+ "%
7
.1fG -- %s\n",
((double) (size))/(1024.0 * 1024.0 * 1024.0),
filename);
}
((double) (size))/(1024.0 * 1024.0 * 1024.0),
filename);
}