diff --git a/dir.c b/dir.c index b2dfb69eb5..b68750450c 100644 --- a/dir.c +++ b/dir.c @@ -965,6 +965,12 @@ char *get_relative_cwd(char *buffer, int size, const char *dir) case '/': return cwd + 1; default: + /* + * dir can end with a path separator when it's root + * directory. Return proper prefix in that case. + */ + if (dir[-1] == '/') + return cwd; return NULL; } }