diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-02-09 08:21:12 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-02-09 08:21:12 +0530 |
commit | e31867290451d0cd5ee2f34837911cd7d6d9795e (patch) | |
tree | a19f25df4aaee8224b2ecc0310e4da54e962e713 /src/nnn.c | |
parent | 3d5815c5d12f7ca84181e4266f8b4b088dda1e18 (diff) | |
download | nnn-e31867290451d0cd5ee2f34837911cd7d6d9795e.tar.gz |
Fix prefix calcualtion
Diffstat (limited to 'src/nnn.c')
-rw-r--r-- | src/nnn.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -964,21 +964,19 @@ static char *common_prefix(const char *path, char *prefix) while (*x && *y && (*x == *y)) ++x, ++y; - /* Strings are same OR prefix is shorter */ - if ((!*x && !*y) || !*y) + /* Strings are same */ + if (!*x && !*y) return prefix; /* Path is shorter */ - if (!*x) { - xstrlcpy(prefix, path, path - x + 1); + if (!*x && *y == '/') { + xstrlcpy(prefix, path, y - path); return prefix; } - /* Paths deviate and prefix ends with '/' */ - if (y != prefix && *y == '/') { - prefix[y - prefix] = '\0'; + /* Prefix is shorter */ + if (!*y && *x == '/') return prefix; - } /* Shorten prefix */ prefix[y - prefix] = '\0'; |