< prev index next >

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

Print this page
rev 11339 : 8072611: (process) ProcessBuilder redirecting output to file should work with long file names (win)
Reviewed-by: rriggs, simonis
Contributed-by: johannes.scheerer@sap.com, stuefe

@@ -28,10 +28,11 @@
 
 #include "jni.h"
 #include "jvm.h"
 #include "jni_util.h"
 #include "io_util.h"
+#include "io_util_md.h"
 #include <windows.h>
 #include <io.h>
 
 /* We try to make sure that we can read and write 4095 bytes (the
  * fixed limit on Linux) to the pipe on all operating systems without

@@ -465,39 +466,19 @@
 Java_java_lang_ProcessImpl_closeHandle(JNIEnv *env, jclass ignored, jlong handle)
 {
     return (jboolean) CloseHandle((HANDLE) handle);
 }
 
-/**
- * Returns a copy of the Unicode characters of a string. Fow now this
- * function doesn't handle long path names and other issues.
- */
-static WCHAR* getPath(JNIEnv *env, jstring ps) {
-    WCHAR *pathbuf = NULL;
-    const jchar *chars = (*(env))->GetStringChars(env, ps, NULL);
-    if (chars != NULL) {
-        size_t pathlen = wcslen(chars);
-        pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
-        if (pathbuf == NULL) {
-            JNU_ThrowOutOfMemoryError(env, NULL);
-        } else {
-            wcscpy(pathbuf, chars);
-        }
-        (*env)->ReleaseStringChars(env, ps, chars);
-    }
-    return pathbuf;
-}
-
 JNIEXPORT jlong JNICALL
 Java_java_lang_ProcessImpl_openForAtomicAppend(JNIEnv *env, jclass ignored, jstring path)
 {
     const DWORD access = (FILE_GENERIC_WRITE & ~FILE_WRITE_DATA);
     const DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
     const DWORD disposition = OPEN_ALWAYS;
     const DWORD flagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
     HANDLE h;
-    WCHAR *pathbuf = getPath(env, path);
+    WCHAR *pathbuf = pathToNTPath(env, path, JNI_FALSE);
     if (pathbuf == NULL) {
         /* Exception already pending */
         return -1;
     }
     h = CreateFileW(
< prev index next >