diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-06-20 16:28:33 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-06-20 16:29:05 +0200 |
commit | 7e14d8b44db30b06355754a519030fb49dcf7b8f (patch) | |
tree | 45aa961da5aa2d6ba386dc290b638f976bca225e | |
parent | cdd07058705eaef11fcfe4a8fe75e32da6aa5b24 (diff) | |
download | lr-7e14d8b44db30b06355754a519030fb49dcf7b8f.tar.gz lr-7e14d8b44db30b06355754a519030fb49dcf7b8f.tar.xz lr-7e14d8b44db30b06355754a519030fb49dcf7b8f.zip |
lr: allow empty string for .
-rw-r--r-- | lr.1 | 6 | ||||
-rw-r--r-- | lr.c | 18 |
2 files changed, 17 insertions, 7 deletions
diff --git a/lr.1 b/lr.1 index b1e31da..471b68a 100644 --- a/lr.1 +++ b/lr.1 @@ -19,6 +19,12 @@ is a versatile tool to generate file listings with configurable formatting, ordering and filtering. .Pp +When no +.Ar path +is given or +.Ar path +is an empty string, the current directory is used by default. +.Pp The special .Ar path argument 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]); |