X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/blobdiff_plain/6a4287ff3a3c14d68c6f4093ed2eb99a95f1266d..66f0cb51690911c492bba4e94284ccd87c075cf2:/du.c diff --git a/du.c b/du.c index 6d26c34..03276c4 100644 --- a/du.c +++ b/du.c @@ -255,9 +255,18 @@ void du(const char *inpath, gotdata_fn_t gotdata, err_fn_t err, size_t pathlen, pathsize; pathlen = strlen(inpath); + + /* + * Trim any trailing slashes from the input path, otherwise we'll + * store them in the index with confusing effects. + */ + while (pathlen > 1 && inpath[pathlen-1] == '/') + pathlen--; + pathsize = pathlen + 256; path = snewn(pathsize, char); - strcpy(path, inpath); + memcpy(path, inpath, pathlen); + path[pathlen] = '\0'; du_recurse(&path, pathlen, &pathsize, gotdata, err, gotdata_ctx, 1); }