src/java.base/windows/native/libjava/canonicalize_md.c
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Cdiff src/java.base/windows/native/libjava/canonicalize_md.c

src/java.base/windows/native/libjava/canonicalize_md.c

Print this page

        

*** 223,232 **** --- 223,234 ---- jio_fprintf(stderr, "canonicalize: errval %d\n", errval); #endif return 1; } + int wcanonicalize(WCHAR *orig_path, WCHAR *result, int size); + /* Convert a pathname to canonical form. The input orig_path is assumed to have been converted to native form already, via JVM_NativePath(). This is necessary because _fullpath() rejects duplicate separator characters on Win95, though it accepts them on NT. */
*** 235,244 **** --- 237,278 ---- { WIN32_FIND_DATA fd; HANDLE h; char path[1024]; /* Working copy of path */ char *src, *dst, *dend; + wchar_t *worig_path, *wresult; + size_t converted_chars = 0; + + /* handle long path with length >= MAX_PATH */ + if (strlen(orig_path) >= MAX_PATH) { + if ((worig_path = (WCHAR*)malloc(size * sizeof(WCHAR))) == NULL) + return -1; + + if (mbstowcs_s(&converted_chars, worig_path, (size_t)size, orig_path, (size_t)(size - 1)) != 0) { + free(worig_path); + return -1; + } + + if ((wresult = (WCHAR*)malloc(size * sizeof(WCHAR))) == NULL) + return -1; + + if (wcanonicalize(worig_path, wresult, size) != 0) { + free(worig_path); + free(wresult); + return -1; + } + + if (wcstombs_s(&converted_chars, result, (size_t)size, wresult, (size_t)(size - 1)) != 0) { + free(worig_path); + free(wresult); + return -1; + } + + free(worig_path); + free(wresult); + return 0; + } /* Reject paths that contain wildcards */ if (wild(orig_path)) { errno = EINVAL; return -1;
*** 246,256 **** /* Collapse instances of "foo\.." and ensure absoluteness. Note that contrary to the documentation, the _fullpath procedure does not require the drive to be available. It also does not reliably change all occurrences of '/' to '\\' on Win95, so now JVM_NativePath does that. */ ! if(!_fullpath(path, orig_path, sizeof(path))) { return -1; } /* Correction for Win95: _fullpath may leave a trailing "\\" on a UNC pathname */ --- 280,290 ---- /* Collapse instances of "foo\.." and ensure absoluteness. Note that contrary to the documentation, the _fullpath procedure does not require the drive to be available. It also does not reliably change all occurrences of '/' to '\\' on Win95, so now JVM_NativePath does that. */ ! if (!_fullpath(path, orig_path, sizeof(path))) { return -1; } /* Correction for Win95: _fullpath may leave a trailing "\\" on a UNC pathname */
*** 585,595 **** dll, to avoid complicate solution such as including io_util_md.c into that package, as a workaround we put this method here. */ /* copy \\?\ or \\?\UNC\ to the front of path*/ ! WCHAR* getPrefixed(const WCHAR* path, int pathlen) { WCHAR* pathbuf = (WCHAR*)malloc((pathlen + 10) * sizeof (WCHAR)); if (pathbuf != 0) { if (path[0] == L'\\' && path[1] == L'\\') { if (path[2] == L'?' && path[3] == L'\\'){ --- 619,629 ---- dll, to avoid complicate solution such as including io_util_md.c into that package, as a workaround we put this method here. */ /* copy \\?\ or \\?\UNC\ to the front of path*/ ! __declspec(dllexport) WCHAR* getPrefixed(const WCHAR* path, int pathlen) { WCHAR* pathbuf = (WCHAR*)malloc((pathlen + 10) * sizeof (WCHAR)); if (pathbuf != 0) { if (path[0] == L'\\' && path[1] == L'\\') { if (path[2] == L'?' && path[3] == L'\\'){
src/java.base/windows/native/libjava/canonicalize_md.c
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File