Skip to content

Commit 75cfeea

Browse files
committed
squash! mingw: keep trailing slashes when switching directories
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]>
1 parent 381a90a commit 75cfeea

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

compat/mingw.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void process_phantom_symlinks(void)
316316
}
317317

318318
/* Normalizes NT paths as returned by some low-level APIs. */
319-
static wchar_t *normalize_ntpath(wchar_t *wbuf, int strip_trailing_slashes)
319+
static wchar_t *normalize_ntpath(wchar_t *wbuf)
320320
{
321321
int i;
322322
/* fix absolute path prefixes */
@@ -337,10 +337,6 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf, int strip_trailing_slashes)
337337
for (i = 0; wbuf[i]; i++)
338338
if (wbuf[i] == '\\')
339339
wbuf[i] = '/';
340-
/* remove potential trailing slashes */
341-
if (strip_trailing_slashes)
342-
while (i && wbuf[i - 1] == '/')
343-
wbuf[--i] = 0;
344340
return wbuf;
345341
}
346342

@@ -622,7 +618,7 @@ int mingw_chdir(const char *dirname)
622618
CloseHandle(hnd);
623619
}
624620

625-
result = _wchdir(normalize_ntpath(wdirname, 0));
621+
result = _wchdir(normalize_ntpath(wdirname));
626622
current_directory_len = GetCurrentDirectoryW(0, NULL);
627623
return result;
628624
}
@@ -2291,7 +2287,7 @@ int readlink(const char *path, char *buf, size_t bufsiz)
22912287
* so convert to a (hopefully large enough) temporary buffer, then memcpy
22922288
* the requested number of bytes (including '\0' for robustness).
22932289
*/
2294-
if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf, 1), MAX_LONG_PATH)) < 0)
2290+
if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf), MAX_LONG_PATH)) < 0)
22952291
return -1;
22962292
memcpy(buf, tmpbuf, min(bufsiz, len + 1));
22972293
return min(bufsiz, len);

0 commit comments

Comments
 (0)