summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/metaentry.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/metaentry.c b/src/metaentry.c
index da28723..fe1c6d1 100644
--- a/src/metaentry.c
+++ b/src/metaentry.c
@@ -322,16 +322,21 @@ normalize_path(const char *orig)
char *real = realpath(orig, NULL);
char cwd[PATH_MAX];
char *result;
+ size_t cwdlen;
getcwd(cwd, PATH_MAX);
if (!real)
return NULL;
- if (!strncmp(real, cwd, strlen(cwd))) {
- result = xmalloc(strlen(real) - strlen(cwd) + 1 + 1);
+ cwdlen = strlen(cwd);
+ /* If CWD=="/", make cwdlen=0 to not omit slash when building rel path. */
+ cwdlen -= !strcmp("/", cwd);
+
+ if (!strncmp(real, cwd, cwdlen)) {
+ result = xmalloc(strlen(real) - cwdlen + 1 + 1);
result[0] = '\0';
strcat(result, ".");
- strcat(result, real + strlen(cwd));
+ strcat(result, real + cwdlen);
} else {
result = xstrdup(real);
}