From d9472cc252731f39b81b6d4c32bb2474e9c52d1b Mon Sep 17 00:00:00 2001 From: blissful Date: Mon, 15 Apr 2024 23:05:15 -0400 Subject: [PATCH] remove common prefix between strings before comparing them --- src/nnn.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/nnn.c b/src/nnn.c index 0fb74833..3e80f818 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -2854,10 +2854,15 @@ static void write_lastdir(const char *curpath, const char *outfile) * * If the absolute numeric values are same, we fallback to alphasort. */ -static int xstricmp(const char * const s1, const char * const s2) +static int xstricmp(const char *s1, const char *s2) { - char *p1, *p2; + /* Remove the common prefix of both strings. */ + while (*s1 && *s2 && *s1 == *s2) { + s1++; + s2++; + } + char *p1, *p2; long long v1 = strtoll(s1, &p1, 10); long long v2 = strtoll(s2, &p2, 10);