about summary refs log tree commit diff
path: root/lr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lr.c')
-rw-r--r--lr.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/lr.c b/lr.c
index 276abec..17236c5 100644
--- a/lr.c
+++ b/lr.c
@@ -1,7 +1,7 @@
 /* lr - a better recursive ls/find */
 
 /*
- * Copyright (C) 2015-2020 Leah Neukirchen <purl.org/net/chneukirchen>
+ * Copyright (C) 2015-2023 Leah Neukirchen <purl.org/net/chneukirchen>
  * Parts of code derived from musl libc, which is
  * Copyright (C) 2005-2014 Rich Felker, et al.
  *
@@ -31,6 +31,10 @@
 
 #define _GNU_SOURCE
 
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -1459,6 +1463,8 @@ order(const void *a, const void *b)
 		              "ZZZZAZZZZZZZZZZZ"[(fa->sb.st_mode >> 12) & 0x0f]);
 		case 'n': STRCMP(fa->fpath, fb->fpath);
 		case 'N': STRCMP(fb->fpath, fa->fpath);
+		case 'f': STRCMP(basenam(fa->fpath), basenam(fb->fpath));
+		case 'F': STRCMP(basenam(fb->fpath), basenam(fa->fpath));
 		case 'e': STRCMP(extnam(fa->fpath), extnam(fb->fpath));
 		case 'E': STRCMP(extnam(fb->fpath), extnam(fa->fpath));
 		case 'p': DIRCMP(fa->fpath, fb->fpath);
@@ -1628,7 +1634,7 @@ color_size_on(off_t s)
 	else if (s <          512*1024LL) c = 226;
 	else if (s <         1024*1024LL) c = 220;
 	else if (s <     700*1024*1024LL) c = 214;
-	else if (s <  2*1048*1024*1024LL) c = 208;
+	else if (s <  2*1024*1024*1024LL) c = 208;
 	else if (s < 50*1024*1024*1024LL) c = 202;
 	else				  c = 196;
 
@@ -1649,7 +1655,7 @@ print_comma(int len, intmax_t i)
 		*--s = ',';
 	}
 
-	printf("%*.*s", len+len/3, len+len/3, s);
+	printf("%*s", len+len/3, s);
 }
 
 static void
@@ -1782,7 +1788,8 @@ print_noprefix(struct fileinfo *fi)
 	if (fi->prefixl == 0 && fi->fpath[0])
 		print_shquoted(fi->fpath);
 	else if (strlen(fi->fpath) > fi->prefixl + 1)  /* strip prefix */
-		print_shquoted(fi->fpath + fi->prefixl + 1);
+		print_shquoted(fi->fpath + fi->prefixl +
+		    (fi->fpath[fi->prefixl] == '/'));
 	else if (S_ISDIR(fi->sb.st_mode))  /* turn empty string into "." */
 		printf(".");
 	else  /* turn empty string into basename */
@@ -2247,7 +2254,7 @@ static int
 recurse(char *path, struct history *h, int guessdir)
 {
 	size_t l = strlen(path), j = l && path[l-1] == '/' ? l - 1 : l;
-	struct stat st;
+	struct stat st = { 0 };
 	struct history new;
 	int r;
 	ino_t entries;
@@ -2264,7 +2271,7 @@ recurse(char *path, struct history *h, int guessdir)
 	if (need_stat)
 		guessdir = 1;
 
-	if (guessdir && (resolve ? stat(fpath, &st) : lstat(fpath, &st) < 0)) {
+	if (guessdir && (resolve ? stat(fpath, &st) : lstat(fpath, &st)) < 0) {
 		if (resolve && (errno == ENOENT || errno == ELOOP) &&
 		    !lstat(fpath, &st)) {
 			/* ignore */
@@ -2495,7 +2502,7 @@ main(int argc, char *argv[])
 			Gflag += 2;  /* force color on */
 			break;
 		case 'D': Dflag++; Bflag = 0; break;
-		case 'F': format = type_format; break;
+		case 'F': if (!lflag) format = type_format; break;
 		case 'G': Gflag++; break;
 		case 'H': Hflag++; break;
 		case 'L': Lflag++; break;