diff options
author | Leah Neukirchen <leah@vuxu.org> | 2019-12-19 21:14:44 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2019-12-19 21:14:44 +0100 |
commit | d4017bedd9bdadbbccf82a1a3388ef6c5e08426f (patch) | |
tree | d79083a73f8e2052cd5360ea3bd14a5b98623067 | |
parent | 5b4707904748d3bc067900693aeedb14eb78e322 (diff) | |
download | lr-d4017bedd9bdadbbccf82a1a3388ef6c5e08426f.tar.gz lr-d4017bedd9bdadbbccf82a1a3388ef6c5e08426f.tar.xz lr-d4017bedd9bdadbbccf82a1a3388ef6c5e08426f.zip |
recurse: pass guesssubdir with -W
-rw-r--r-- | lr.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lr.c b/lr.c index 9bafe3b..0c896d0 100644 --- a/lr.c +++ b/lr.c @@ -2230,11 +2230,16 @@ struct history { off_t total; }; +struct names { + char *path; + int guessdir; +}; + int cmpstr(void const *a, void const *b) { - char const **aa = (char const **)a; - char const **bb = (char const **)b; + struct names *aa = (struct names *)a; + struct names *bb = (struct names *)b; - return strcmp(*aa, *bb); + return strcmp(aa->path, bb->path); } /* NB: path is expected to have MAXPATHLEN space used in recursive calls. */ @@ -2247,7 +2252,7 @@ recurse(char *path, struct history *h, int guessdir) int r; ino_t entries; const char *fpath = *path ? path : "."; - char **names = 0; + struct names *names = 0, *tmp; size_t len = 0; int resolve = Lflag || (Hflag && !h); @@ -2335,14 +2340,15 @@ recurse(char *path, struct history *h, int guessdir) /* store paths in names for later sorting */ if (entries >= len) { len = 2 * len + 1; - if (len > SIZE_MAX/sizeof (char *)) + if (len > SIZE_MAX/sizeof *names) break; - char **tmp = realloc(names, len * sizeof *names); + tmp = realloc(names, len * sizeof *names); if (!tmp) break; names = tmp; } - names[entries-1] = strdup(path); + names[entries-1].path = strdup(path); + names[entries-1].guessdir = guesssubdir; } else if ((r = recurse(path, &new, guesssubdir))) { closedir(d); return r; @@ -2357,16 +2363,16 @@ recurse(char *path, struct history *h, int guessdir) if (Wflag && names) { size_t i; - qsort(names, entries, sizeof (char *), cmpstr); + qsort(names, entries, sizeof *names, cmpstr); for (i = 0; i < entries; i++) { - strcpy(path, names[i]); - recurse(path, &new, 1); + strcpy(path, names[i].path); + recurse(path, &new, names[i].guessdir); } /* ensure cleanup in reverse allocation order */ for (i = 0; i < entries; i++) - free(names[entries-i-1]); + free(names[entries-i-1].path); free(names); } |