mirror of
https://github.com/jarun/nnn.git
synced 2025-02-26 03:01:32 +00:00
Fix prefix calcualtion
This commit is contained in:
parent
3d5815c5d1
commit
e318672904
1 changed files with 6 additions and 8 deletions
14
src/nnn.c
14
src/nnn.c
|
@ -964,21 +964,19 @@ static char *common_prefix(const char *path, char *prefix)
|
||||||
while (*x && *y && (*x == *y))
|
while (*x && *y && (*x == *y))
|
||||||
++x, ++y;
|
++x, ++y;
|
||||||
|
|
||||||
/* Strings are same OR prefix is shorter */
|
/* Strings are same */
|
||||||
if ((!*x && !*y) || !*y)
|
if (!*x && !*y)
|
||||||
return prefix;
|
return prefix;
|
||||||
|
|
||||||
/* Path is shorter */
|
/* Path is shorter */
|
||||||
if (!*x) {
|
if (!*x && *y == '/') {
|
||||||
xstrlcpy(prefix, path, path - x + 1);
|
xstrlcpy(prefix, path, y - path);
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paths deviate and prefix ends with '/' */
|
/* Prefix is shorter */
|
||||||
if (y != prefix && *y == '/') {
|
if (!*y && *x == '/')
|
||||||
prefix[y - prefix] = '\0';
|
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
|
||||||
|
|
||||||
/* Shorten prefix */
|
/* Shorten prefix */
|
||||||
prefix[y - prefix] = '\0';
|
prefix[y - prefix] = '\0';
|
||||||
|
|
Loading…
Add table
Reference in a new issue