author | msheppar |
Thu, 20 Mar 2014 21:03:43 +0000 | |
changeset 23556 | 1726e34c34e8 |
parent 22641 | e47f8892133e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
#include <stdlib.h> |
|
26 |
||
27 |
#include "jni.h" |
|
28 |
#include "jni_util.h" |
|
29 |
#include <windows.h> |
|
30 |
||
31 |
static jstring |
|
32 |
environmentBlock9x(JNIEnv *env) |
|
33 |
{ |
|
34 |
int i; |
|
22641
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
35 |
jmethodID String_init_ID; |
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
36 |
jbyteArray bytes; |
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
37 |
jbyte *blockA; |
23556
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
38 |
jclass string_class; |
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
39 |
|
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
40 |
string_class = JNU_ClassString(env); |
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
41 |
CHECK_NULL_RETURN(string_class, NULL); |
22641
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
42 |
|
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
43 |
String_init_ID = |
23556
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
44 |
(*env)->GetMethodID(env, string_class, "<init>", "([B)V"); |
22641
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
45 |
CHECK_NULL_RETURN(String_init_ID, NULL); |
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
46 |
|
e47f8892133e
8033372: Check jdk/src/share/native/java/lang for JNI pending exception issues
alanb
parents:
5506
diff
changeset
|
47 |
blockA = (jbyte *) GetEnvironmentStringsA(); |
2 | 48 |
if (blockA == NULL) { |
49 |
/* Both GetEnvironmentStringsW and GetEnvironmentStringsA |
|
50 |
* failed. Out of memory is our best guess. */ |
|
51 |
JNU_ThrowOutOfMemoryError(env, "GetEnvironmentStrings failed"); |
|
52 |
return NULL; |
|
53 |
} |
|
54 |
||
55 |
/* Don't search for "\0\0", since an empty environment block may |
|
56 |
legitimately consist of a single "\0". */ |
|
57 |
for (i = 0; blockA[i];) |
|
58 |
while (blockA[i++]) |
|
59 |
; |
|
60 |
||
23556
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
61 |
if ((bytes = (*env)->NewByteArray(env, i)) == NULL) { |
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
62 |
FreeEnvironmentStringsA(blockA); |
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
63 |
return NULL; |
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
64 |
} |
2 | 65 |
(*env)->SetByteArrayRegion(env, bytes, 0, i, blockA); |
66 |
FreeEnvironmentStringsA(blockA); |
|
23556
1726e34c34e8
8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions
msheppar
parents:
22641
diff
changeset
|
67 |
return (*env)->NewObject(env, string_class, |
2 | 68 |
String_init_ID, bytes); |
69 |
} |
|
70 |
||
71 |
/* Returns a Windows style environment block, discarding final trailing NUL */ |
|
72 |
JNIEXPORT jstring JNICALL |
|
73 |
Java_java_lang_ProcessEnvironment_environmentBlock(JNIEnv *env, jclass klass) |
|
74 |
{ |
|
75 |
int i; |
|
76 |
jstring envblock; |
|
77 |
jchar *blockW = (jchar *) GetEnvironmentStringsW(); |
|
78 |
if (blockW == NULL) |
|
79 |
return environmentBlock9x(env); |
|
80 |
||
81 |
/* Don't search for "\u0000\u0000", since an empty environment |
|
82 |
block may legitimately consist of a single "\u0000". */ |
|
83 |
for (i = 0; blockW[i];) |
|
84 |
while (blockW[i++]) |
|
85 |
; |
|
86 |
||
87 |
envblock = (*env)->NewString(env, blockW, i); |
|
88 |
FreeEnvironmentStringsW(blockW); |
|
89 |
return envblock; |
|
90 |
} |