43c2197b49
* correctly handle cumulative size for directory / rather than treat it as a file named "" under directory / (Seen with 'du /|xdu') * handle filenames with whitespace chars (but not [\r\n]) (jakob@ ok)
82 lines
1.7 KiB
Plaintext
82 lines
1.7 KiB
Plaintext
|
|
* Allow filenames with whitespace characters (not CR or LF though)
|
|
* Correctly handle root directory entry ("/")
|
|
|
|
--- xdu.c.orig Mon Apr 24 09:01:53 2000
|
|
+++ xdu.c Mon Apr 24 10:08:07 2000
|
|
@@ -234,6 +234,7 @@
|
|
char name[4096];
|
|
int size;
|
|
FILE *fp;
|
|
+ char *p, *n;
|
|
|
|
if (strcmp(filename, "-") == 0) {
|
|
fp = stdin;
|
|
@@ -243,11 +244,21 @@
|
|
exit(1);
|
|
}
|
|
}
|
|
+
|
|
while (fgets(buf,sizeof(buf),fp) != NULL) {
|
|
- sscanf(buf, "%d %s\n", &size, name);
|
|
+ p = buf;
|
|
+ while (*p && isspace(*p)) p++;
|
|
+ size = atoi(p);
|
|
+ while (*p && !isspace(*p)) p++;
|
|
+ while (*p && isspace(*p)) p++;
|
|
+ n = name;
|
|
+ while (*p && *p != '\n' && *p != '\r')
|
|
+ *n++ = *p++;
|
|
+ *n++ = '\0';
|
|
/*printf("%d %s\n", size, name);*/
|
|
parse_entry(name,size);
|
|
}
|
|
+
|
|
fclose(fp);
|
|
}
|
|
|
|
@@ -268,7 +279,7 @@
|
|
length = strlen(name);
|
|
if ((length > 0) && (name[length-1] == '/')) {
|
|
/* strip off trailing / (e.g. GNU du) */
|
|
- name[length-1] = 0;
|
|
+ name[--length] = 0;
|
|
}
|
|
|
|
arg = 0; indx = 0;
|
|
@@ -288,8 +299,10 @@
|
|
}
|
|
name++;
|
|
}
|
|
- buf[indx] = 0;
|
|
- path[arg++] = strdup(buf);
|
|
+ if (length) {
|
|
+ buf[indx] = 0;
|
|
+ path[arg++] = strdup(buf);
|
|
+ }
|
|
path[arg] = NULL;
|
|
|
|
addtree(&top,path,size);
|
|
@@ -398,15 +411,15 @@
|
|
|
|
/*printf("addtree(\"%s\",\"%s\",%d)\n", top->name, path[0], size);*/
|
|
|
|
+ if (path[0] == NULL) {
|
|
+ /* end of the chain, save size */
|
|
+ top->size = size;
|
|
+ return;
|
|
+ }
|
|
+
|
|
/* check all children for a match */
|
|
for (np = top->child; np != NULL; np = np->peer) {
|
|
if (strcmp(path[0],np->name) == 0) {
|
|
- /* name matches */
|
|
- if (path[1] == NULL) {
|
|
- /* end of the chain, save size */
|
|
- np->size = size;
|
|
- return;
|
|
- }
|
|
/* recurse */
|
|
addtree(np,&path[1],size);
|
|
return;
|