Skip to content

Commit

Permalink
squash! mingw: keep trailing slashes when switching directories
Browse files Browse the repository at this point in the history
Actually, we should always keep the trailing slashes as both users of
`normalize_ntpath()` require them: `_wchdir()` wants the slash in
particular when changing the directory to a drive root, and
`readlink()`'s semantics require a trailing slash for symbolic links
pointing to directories.

This fixes #210

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Jun 20, 2015
1 parent 381a90a commit 75cfeea
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static void process_phantom_symlinks(void)
}

/* Normalizes NT paths as returned by some low-level APIs. */
static wchar_t *normalize_ntpath(wchar_t *wbuf, int strip_trailing_slashes)
static wchar_t *normalize_ntpath(wchar_t *wbuf)
{
int i;
/* fix absolute path prefixes */
Expand All @@ -337,10 +337,6 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf, int strip_trailing_slashes)
for (i = 0; wbuf[i]; i++)
if (wbuf[i] == '\\')
wbuf[i] = '/';
/* remove potential trailing slashes */
if (strip_trailing_slashes)
while (i && wbuf[i - 1] == '/')
wbuf[--i] = 0;
return wbuf;
}

Expand Down Expand Up @@ -622,7 +618,7 @@ int mingw_chdir(const char *dirname)
CloseHandle(hnd);
}

result = _wchdir(normalize_ntpath(wdirname, 0));
result = _wchdir(normalize_ntpath(wdirname));
current_directory_len = GetCurrentDirectoryW(0, NULL);
return result;
}
Expand Down Expand Up @@ -2291,7 +2287,7 @@ int readlink(const char *path, char *buf, size_t bufsiz)
* so convert to a (hopefully large enough) temporary buffer, then memcpy
* the requested number of bytes (including '\0' for robustness).
*/
if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf, 1), MAX_LONG_PATH)) < 0)
if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf), MAX_LONG_PATH)) < 0)
return -1;
memcpy(buf, tmpbuf, min(bufsiz, len + 1));
return min(bufsiz, len);
Expand Down

0 comments on commit 75cfeea

Please sign in to comment.