46 char *p, *r; 47 48 /* If no spaces, then use entire thing */ 49 if ((p = strchr(source, ' ')) == NULL) 50 return source; 51 52 /* If no quotes, or quotes after space, return up to space */ 53 if (((r = strchr(source, '"')) == NULL) || (r > p)) { 54 *p = 0; 55 return source; 56 } 57 58 /* Quotes before space, return up to space after next quotes */ 59 p = strchr(r, '"'); 60 if ((p = strchr(p, ' ')) == NULL) 61 return source; 62 *p = 0; 63 return source; 64 } 65 66 DWORD 67 selectProcessFlag(JNIEnv *env, jstring cmd0) 68 { 69 char buf[MAX_PATH]; 70 DWORD newFlag = 0; 71 char *exe, *p, *name; 72 unsigned char buffer[2]; 73 long headerLoc = 0; 74 int fd = 0; 75 76 exe = (char *)JNU_GetStringPlatformChars(env, cmd0, 0); 77 exe = extractExecutablePath(env, exe); 78 79 if (exe != NULL) { 80 if ((p = strchr(exe, '\\')) == NULL) { 81 SearchPath(NULL, exe, ".exe", MAX_PATH, buf, &name); 82 } else { 83 p = strrchr(exe, '\\'); 84 *p = 0; 85 p++; 86 SearchPath(exe, p, ".exe", MAX_PATH, buf, &name); 87 } 88 } 89 90 fd = _open(buf, _O_RDONLY); 91 if (fd > 0) { 92 _read(fd, buffer, 2); 93 if (buffer[0] == 'M' && buffer[1] == 'Z') { 94 _lseek(fd, 60L, SEEK_SET); 95 _read(fd, buffer, 2); 96 headerLoc = (long)buffer[1] << 8 | (long)buffer[0]; 97 _lseek(fd, headerLoc, SEEK_SET); 98 _read(fd, buffer, 2); 99 if (buffer[0] == 'P' && buffer[1] == 'E') { 100 newFlag = DETACHED_PROCESS; 101 } 102 } 103 _close(fd); 104 } 105 JNU_ReleaseStringPlatformChars(env, cmd0, exe); 106 return newFlag; 107 } 108 109 static void 110 win32Error(JNIEnv *env, const char *functionName) 111 { 112 static const char * const format = "%s error=%d, %s"; 113 static const char * const fallbackFormat = "%s failed, error=%d"; 114 char buf[256]; 115 char errmsg[sizeof(buf) + 100]; 116 const int errnum = GetLastError(); 117 const int n = JVM_GetLastErrorString(buf, sizeof(buf)); 118 if (n > 0) 119 sprintf(errmsg, format, functionName, errnum, buf); 120 else 121 sprintf(errmsg, fallbackFormat, functionName, errnum); 122 JNU_ThrowIOException(env, errmsg); 123 } 124 125 static void | 46 char *p, *r; 47 48 /* If no spaces, then use entire thing */ 49 if ((p = strchr(source, ' ')) == NULL) 50 return source; 51 52 /* If no quotes, or quotes after space, return up to space */ 53 if (((r = strchr(source, '"')) == NULL) || (r > p)) { 54 *p = 0; 55 return source; 56 } 57 58 /* Quotes before space, return up to space after next quotes */ 59 p = strchr(r, '"'); 60 if ((p = strchr(p, ' ')) == NULL) 61 return source; 62 *p = 0; 63 return source; 64 } 65 66 static const char EXE_EXT[] = ".exe"; 67 68 DWORD 69 selectProcessFlag(JNIEnv *env, jstring cmd0) 70 { 71 DWORD newFlag = 0; 72 char *exe = (char *)JNU_GetStringPlatformChars(env, cmd0, 0); 73 if (exe != NULL) { 74 char buf[MAX_PATH]; 75 char *name; 76 DWORD len; 77 exe = extractExecutablePath(env, exe); 78 if (exe != NULL) { 79 /*we are here for Win9x/Me, so the [/] is not the path sep*/ 80 char *p = strrchr(exe, '\\'); 81 if (p == NULL) { 82 len = SearchPath(NULL, exe, EXE_EXT, MAX_PATH, buf, &name); 83 } else { 84 *p = 0; 85 len = SearchPath(exe, p + 1, EXE_EXT, MAX_PATH, buf, &name); 86 } 87 } 88 89 if (len > 0 && len < MAX_PATH) { 90 /*here the [buf] path is null terminated*/ 91 int fd = _open(buf, _O_RDONLY); 92 if (fd != -1) { 93 unsigned char buffer[2]; 94 if (_read(fd, buffer, 2) == 2 95 && buffer[0] == 'M' && buffer[1] == 'Z' 96 && _lseek(fd, 60L, SEEK_SET) == 60L 97 && _read(fd, buffer, 2) == 2) 98 { 99 long headerLoc = (long)buffer[1] << 8 | (long)buffer[0]; 100 if (_lseek(fd, headerLoc, SEEK_SET) == headerLoc 101 && _read(fd, buffer, 2) == 2 102 && buffer[0] == 'P' && buffer[1] == 'E') 103 { 104 newFlag = DETACHED_PROCESS; 105 } 106 } 107 _close(fd); 108 } 109 } 110 JNU_ReleaseStringPlatformChars(env, cmd0, exe); 111 } 112 return newFlag; 113 } 114 115 static void 116 win32Error(JNIEnv *env, const char *functionName) 117 { 118 static const char * const format = "%s error=%d, %s"; 119 static const char * const fallbackFormat = "%s failed, error=%d"; 120 char buf[256]; 121 char errmsg[sizeof(buf) + 100]; 122 const int errnum = GetLastError(); 123 const int n = JVM_GetLastErrorString(buf, sizeof(buf)); 124 if (n > 0) 125 sprintf(errmsg, format, functionName, errnum, buf); 126 else 127 sprintf(errmsg, fallbackFormat, functionName, errnum); 128 JNU_ThrowIOException(env, errmsg); 129 } 130 131 static void |