diff options
author | Sverker Eriksson <[email protected]> | 2014-03-13 14:30:38 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2014-03-13 14:30:38 +0100 |
commit | eec90640fb8d122dd713d2c892fa2c365c05aae6 (patch) | |
tree | 7e5fa39f321420786c9636e628ad814e2d4acad9 /erts/emulator/drivers/win32 | |
parent | fe00fbc345a58ad4313ba34ec303784353ec6039 (diff) | |
download | otp-eec90640fb8d122dd713d2c892fa2c365c05aae6.tar.gz otp-eec90640fb8d122dd713d2c892fa2c365c05aae6.tar.bz2 otp-eec90640fb8d122dd713d2c892fa2c365c05aae6.zip |
erts: Use GetFullPathNameW to construct abs paths from relative ones
Diffstat (limited to 'erts/emulator/drivers/win32')
-rw-r--r-- | erts/emulator/drivers/win32/win_efile.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/erts/emulator/drivers/win32/win_efile.c b/erts/emulator/drivers/win32/win_efile.c index e4a7dac1df..d9bc390d13 100644 --- a/erts/emulator/drivers/win32/win_efile.c +++ b/erts/emulator/drivers/win32/win_efile.c @@ -361,6 +361,8 @@ static void ensure_wpath_max(Efile_call_state* state, WCHAR** pathp, size_t max) return; } + SVERK_TRACE1(8,"IN: %s", path); + if (path[1] == L':' && ISSLASH(path[2])) { /* absolute path */ if (len >= max) { WCHAR *src, *dst; @@ -378,33 +380,31 @@ static void ensure_wpath_max(Efile_call_state* state, WCHAR** pathp, size_t max) DWORD cwdLen = GetCurrentDirectoryW(0, NULL); DWORD absLen = cwdLen + 1 + len; if (absLen >= max) { - WCHAR *cwd; - - cwd = wpath_tmp_alloc(state, 4+absLen); - wcscpy(cwd, L"\\\\?\\"); - cwdLen = GetCurrentDirectoryW(cwdLen, cwd+4); - if (wcsncmp(cwd+4, L"\\\\?\\", 4) == 0) { - cwd += 4; - cwdLen -= 4; + WCHAR *fullPath = wpath_tmp_alloc(state, 4+4+absLen); + DWORD fullLen; + + fullLen = GetFullPathNameW(path, 4 + absLen, fullPath+4, NULL); + if (fullLen >= 4+absLen) { + *pathp = path; + SVERK_TRACE2(8,"ensure_wpath FAILED absLen=%u %s", (int)absLen, path); + return; + } + /* GetFullPathNameW can return paths longer than MAX_PATH without the \\?\ prefix. + * At least seen on Windows 7. Go figure... + */ + if (fullLen >= max && wcsncmp(fullPath+4, L"\\\\?\\", 4) != 0) { + wcsncpy(fullPath, L"\\\\?\\", 4); + *pathp = fullPath; + } + else { + *pathp = fullPath + 4; } - p = cwd + 4 + cwdLen; - if (!ISSLASH(p[-1])) - *p++ = L'\\'; - wcscpy(p, path); - - for (p=cwd; *p; p++) - if (*p == L'/') - *p = L'\\'; - *pathp = cwd; - unc_fixup = 1; } } if (unc_fixup) { WCHAR* endp; - SVERK_TRACE1(8,"IN: %s", path); - p = *pathp; len = wcslen(p); endp = p + len; @@ -432,8 +432,8 @@ static void ensure_wpath_max(Efile_call_state* state, WCHAR** pathp, size_t max) else ++p; } } - SVERK_TRACE1(8,"OUT: %s", *pathp); } + SVERK_TRACE1(8,"OUT: %s", *pathp); } int |