author | jwilhelm |
Thu, 27 Jun 2019 03:13:54 +0200 | |
changeset 55515 | 4c52949a3487 |
parent 50471 | f0aeede1b855 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, 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 |
||
26 |
#include <stdlib.h> |
|
27 |
#include <windows.h> |
|
23562
596efd9dfcaf
8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents:
22951
diff
changeset
|
28 |
#include "jni.h" |
596efd9dfcaf
8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents:
22951
diff
changeset
|
29 |
#include "jni_util.h" |
596efd9dfcaf
8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents:
22951
diff
changeset
|
30 |
#include "jvm.h" |
50471
f0aeede1b855
8204572: SetupJdkLibrary should setup SRC and -I flags automatically
ihse
parents:
49154
diff
changeset
|
31 |
#include "java_util_prefs_WindowsPreferences.h" |
f0aeede1b855
8204572: SetupJdkLibrary should setup SRC and -I flags automatically
ihse
parents:
49154
diff
changeset
|
32 |
|
2 | 33 |
#ifdef __cplusplus |
34 |
extern "C" { |
|
35 |
#endif |
|
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
36 |
|
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
37 |
/* |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
38 |
* Declare library specific JNI_Onload entry if static build |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
39 |
*/ |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
40 |
DEF_STATIC_JNI_OnLoad |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
41 |
|
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
42 |
JNIEXPORT jlongArray JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
43 |
Java_java_util_prefs_WindowsPreferences_WindowsRegOpenKey(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
44 |
jclass this_class, jlong hKey, jbyteArray lpSubKey, jint securityMask) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
45 |
char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
46 |
CHECK_NULL_RETURN(str, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
47 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
48 |
HKEY handle; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
49 |
int errorCode = RegOpenKeyEx((HKEY) hKey, str, 0, securityMask, &handle); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
50 |
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
51 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
52 |
jlong tmp[2]; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
53 |
tmp[0] = (jlong) handle; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
54 |
tmp[1] = errorCode; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
55 |
jlongArray result = (*env)->NewLongArray(env, 2); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
56 |
if (result != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
57 |
(*env)->SetLongArrayRegion(env, result, 0, 2, tmp); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
58 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
59 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
60 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
61 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
62 |
JNIEXPORT jint JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
63 |
Java_java_util_prefs_WindowsPreferences_WindowsRegCloseKey(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
64 |
jclass this_class, jlong hKey) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
65 |
return (jint) RegCloseKey((HKEY) hKey); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
66 |
}; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
67 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
68 |
JNIEXPORT jlongArray JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
69 |
Java_java_util_prefs_WindowsPreferences_WindowsRegCreateKeyEx(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
70 |
jclass this_class, jlong hKey, jbyteArray lpSubKey) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
71 |
char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
72 |
CHECK_NULL_RETURN(str, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
73 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
74 |
HKEY handle; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
75 |
DWORD lpdwDisposition; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
76 |
int errorCode = RegCreateKeyEx((HKEY) hKey, str, 0, NULL, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
77 |
REG_OPTION_NON_VOLATILE, KEY_READ, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
78 |
NULL, &handle, &lpdwDisposition); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
79 |
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
80 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
81 |
jlong tmp[3]; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
82 |
tmp[0] = (jlong) handle; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
83 |
tmp[1] = errorCode; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
84 |
tmp[2] = lpdwDisposition; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
85 |
jlongArray result = (*env)->NewLongArray(env, 3); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
86 |
if (result != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
87 |
(*env)->SetLongArrayRegion(env, result, 0, 3, tmp); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
88 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
89 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
90 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
91 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
92 |
JNIEXPORT jint JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
93 |
Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteKey(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
94 |
jclass this_class, jlong hKey, jbyteArray lpSubKey) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
95 |
char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
96 |
CHECK_NULL_RETURN(str, -1); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
97 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
98 |
int result = RegDeleteKey((HKEY) hKey, str); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
99 |
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
100 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
101 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
102 |
}; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
103 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
104 |
JNIEXPORT jint JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
105 |
Java_java_util_prefs_WindowsPreferences_WindowsRegFlushKey(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
106 |
jclass this_class, jlong hKey) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
107 |
return RegFlushKey((HKEY) hKey); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
108 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
109 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
110 |
JNIEXPORT jbyteArray JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
111 |
Java_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
112 |
jclass this_class, jlong hKey, jbyteArray valueName) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
113 |
char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
114 |
CHECK_NULL_RETURN(valueNameStr, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
115 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
116 |
DWORD valueType; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
117 |
DWORD valueSize; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
118 |
if (RegQueryValueEx((HKEY) hKey, valueNameStr, NULL, &valueType, NULL, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
119 |
&valueSize) != ERROR_SUCCESS) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
120 |
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
121 |
return NULL; |
2 | 122 |
} |
123 |
||
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
124 |
char* buffer = (char*) malloc(valueSize); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
125 |
if (buffer != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
126 |
if (RegQueryValueEx((HKEY) hKey, valueNameStr, NULL, &valueType, buffer, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
127 |
&valueSize) != ERROR_SUCCESS) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
128 |
free(buffer); |
2 | 129 |
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); |
23562
596efd9dfcaf
8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents:
22951
diff
changeset
|
130 |
return NULL; |
2 | 131 |
} |
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
132 |
} else { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
133 |
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); |
2 | 134 |
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); |
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
135 |
return NULL; |
2 | 136 |
} |
137 |
||
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
138 |
jbyteArray result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
139 |
if (valueType == REG_SZ) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
140 |
result = (*env)->NewByteArray(env, valueSize); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
141 |
if (result != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
142 |
(*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
143 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
144 |
} else { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
145 |
result = NULL; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
146 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
147 |
free(buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
148 |
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
149 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
150 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
151 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
152 |
JNIEXPORT jint JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
153 |
Java_java_util_prefs_WindowsPreferences_WindowsRegSetValueEx(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
154 |
jclass this_class, jlong hKey, jbyteArray valueName, jbyteArray data) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
155 |
if ((valueName == NULL) || (data == NULL)) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
156 |
return -1; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
157 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
158 |
int size = (*env)->GetArrayLength(env, data); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
159 |
char* dataStr = (*env)->GetByteArrayElements(env, data, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
160 |
CHECK_NULL_RETURN(dataStr, -1); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
161 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
162 |
char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
163 |
int error_code = -1; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
164 |
if (valueNameStr != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
165 |
error_code = RegSetValueEx((HKEY) hKey, valueNameStr, 0, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
166 |
REG_SZ, dataStr, size); |
2 | 167 |
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); |
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
168 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
169 |
(*env)->ReleaseByteArrayElements(env, data, dataStr, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
170 |
return error_code; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
171 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
172 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
173 |
JNIEXPORT jint JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
174 |
Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteValue(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
175 |
jclass this_class, jlong hKey, jbyteArray valueName) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
176 |
if (valueName == NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
177 |
return -1; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
178 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
179 |
char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
180 |
CHECK_NULL_RETURN(valueNameStr, -1); |
2 | 181 |
|
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
182 |
int error_code = RegDeleteValue((HKEY) hKey, valueNameStr); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
183 |
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
184 |
return error_code; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
185 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
186 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
187 |
JNIEXPORT jlongArray JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
188 |
Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
189 |
jclass this_class, jlong hKey) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
190 |
int subKeysNumber; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
191 |
int maxSubKeyLength; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
192 |
int valuesNumber; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
193 |
int maxValueNameLength; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
194 |
int errorCode = RegQueryInfoKey((HKEY) hKey, NULL, NULL, NULL, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
195 |
&subKeysNumber, &maxSubKeyLength, NULL, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
196 |
&valuesNumber, &maxValueNameLength, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
197 |
NULL, NULL, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
198 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
199 |
jlong tmp[5]; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
200 |
tmp[0] = subKeysNumber; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
201 |
tmp[1] = errorCode; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
202 |
tmp[2] = valuesNumber; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
203 |
tmp[3] = maxSubKeyLength; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
204 |
tmp[4] = maxValueNameLength; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
205 |
jintArray result = (*env)->NewLongArray(env, 5); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
206 |
if (result != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
207 |
(*env)->SetLongArrayRegion(env, result, 0, 5, tmp); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
208 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
209 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
210 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
211 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
212 |
JNIEXPORT jbyteArray JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
213 |
Java_java_util_prefs_WindowsPreferences_WindowsRegEnumKeyEx(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
214 |
jclass this_class, jlong hKey, jint subKeyIndex, jint maxKeyLength) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
215 |
int size = maxKeyLength; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
216 |
char* buffer = (char*) malloc(maxKeyLength); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
217 |
if (buffer == NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
218 |
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
219 |
return NULL; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
220 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
221 |
if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
222 |
NULL, NULL) != ERROR_SUCCESS) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
223 |
free(buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
224 |
return NULL; |
2 | 225 |
} |
226 |
||
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
227 |
jbyteArray result = (*env)->NewByteArray(env, size + 1); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
228 |
if (result != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
229 |
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
230 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
231 |
free(buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
232 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
233 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
234 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
235 |
JNIEXPORT jbyteArray JNICALL |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
236 |
Java_java_util_prefs_WindowsPreferences_WindowsRegEnumValue(JNIEnv* env, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
237 |
jclass this_class, jlong hKey, jint valueIndex, jint maxValueNameLength) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
238 |
int size = maxValueNameLength; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
239 |
char* buffer = (char*) malloc(maxValueNameLength); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
240 |
if (buffer == NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
241 |
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
242 |
return NULL; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
243 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
244 |
|
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
245 |
int error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer, |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
246 |
&size, NULL, NULL, NULL, NULL); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
247 |
if (error_code != ERROR_SUCCESS) { |
2 | 248 |
free(buffer); |
249 |
return NULL; |
|
49154
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
250 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
251 |
jbyteArray result = (*env)->NewByteArray(env, size + 1); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
252 |
if (result != NULL) { |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
253 |
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
254 |
} |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
255 |
free(buffer); |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
256 |
return result; |
28729cf7e4bc
8198899: Compilation errors in java.prefs with VS 2017
bpb
parents:
47216
diff
changeset
|
257 |
} |
2 | 258 |
|
259 |
||
260 |
#ifdef __cplusplus |
|
261 |
} |
|
262 |
#endif |