about summary refs log tree commit diff
path: root/lr.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-06-20 16:28:33 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-06-20 16:29:05 +0200
commit7e14d8b44db30b06355754a519030fb49dcf7b8f (patch)
tree45aa961da5aa2d6ba386dc290b638f976bca225e /lr.c
parentcdd07058705eaef11fcfe4a8fe75e32da6aa5b24 (diff)
downloadlr-7e14d8b44db30b06355754a519030fb49dcf7b8f.tar.gz
lr-7e14d8b44db30b06355754a519030fb49dcf7b8f.tar.xz
lr-7e14d8b44db30b06355754a519030fb49dcf7b8f.zip
lr: allow empty string for .
Diffstat (limited to 'lr.c')
-rw-r--r--lr.c18
1 files changed, 11 insertions, 7 deletions
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]);