Browse Source

Fix prefix calcualtion

master
Arun Prakash Jana 5 years ago
parent
commit
e318672904
No known key found for this signature in database GPG Key ID: A75979F35C080412
1 changed files with 6 additions and 8 deletions
  1. +6
    -8
      src/nnn.c

+ 6
- 8
src/nnn.c View File

@@ -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';


Loading…
Cancel
Save