summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lr.16
-rw-r--r--lr.c18
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]);