From 7e14d8b44db30b06355754a519030fb49dcf7b8f Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Tue, 20 Jun 2017 16:28:33 +0200 Subject: lr: allow empty string for . --- lr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lr.c') diff --git a/lr.c b/lr.c index bf7590d..02cc82c 100644 --- a/lr.c +++ b/lr.c @@ -1758,11 +1758,12 @@ recurse(char *path, struct history *h) struct stat st; struct history new; int r, entries; + const char *fpath = *path ? path : "."; int resolve = Lflag || (Hflag && !h); - if (resolve ? stat(path, &st) : lstat(path, &st) < 0) { - if (resolve && errno == ENOENT && !lstat(path, &st)) + if (resolve ? stat(fpath, &st) : lstat(fpath, &st) < 0) { + if (resolve && errno == ENOENT && !lstat(fpath, &st)) ; else if (errno != EACCES) return -1; @@ -1794,7 +1795,7 @@ recurse(char *path, struct history *h) } if (S_ISDIR(st.st_mode)) { - DIR *d = opendir(path); + DIR *d = opendir(fpath); if (d) { struct dirent *de; while ((de = readdir(d))) { @@ -1808,8 +1809,12 @@ recurse(char *path, struct history *h) closedir(d); return -1; } - path[j] = '/'; - strcpy(path + j + 1, de->d_name); + if (j > 0) { + path[j] = '/'; + strcpy(path + j + 1, de->d_name); + } else { + strcpy(path, de->d_name); + } if ((r = recurse(path, &new))) { closedir(d); return r; @@ -1941,8 +1946,7 @@ main(int argc, char *argv[]) analyze_format(); if (optind == argc) { - sflag++; - traverse("."); + traverse(""); } else { for (i = optind; i < argc; i++) traverse(argv[i]); -- cgit 1.4.1