How does Java circumvent the windows MAX_PATH WinAPI limitation

后端 未结 3 1737
Happy的楠姐
Happy的楠姐 2021-01-19 22:38

Does anyone know how Java is able to circumvent the windows MAX_PATH limitations. Using the below code I was able to create a really long path in Java and was able to perfor

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-19 22:45

    From the JVM's canonicalize_md.c:

    /* copy \\?\ or \\?\UNC\ to the front of path*/
    WCHAR* getPrefixed(const WCHAR* path, int pathlen) {
        [download JVM source code (below) to see implementation]
    }
    

    The function getPrefixed is called:

    • by the function wcanonicalize if ((pathlen = wcslen(path)) > MAX_PATH - 1)
    • by the function wcanonicalizeWithPrefix.

    I didn't trace the call chain farther than that, but I assume the JVM always uses these canonicalization routines before accessing the filesystem, and so always hits this code one way or another. If you want to trace the call chain farther yourself, you too can partake in the joys of browsing the JVM source code! Download at: http://download.java.net/openjdk/jdk6/

提交回复
热议问题