src/java.prefs/windows/native/libprefs/WindowsPreferences.c
author redestad
Tue, 27 Feb 2018 21:05:07 +0100
changeset 48993 aef762ff9b23
parent 47216 71c04702a3d5
child 49154 28729cf7e4bc
permissions -rw-r--r--
8198755: Reduce cost of InvokerBytecodeGenerator::isStaticallyInvocable/-Nameable Reviewed-by: vlivanov, psandoz, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
extern "C" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    34
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    35
/*
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    36
 * 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
    37
 */
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    38
DEF_STATIC_JNI_OnLoad
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 25859
diff changeset
    39
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegOpenKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
               (JNIEnv* env, jclass this_class, jint hKey, jbyteArray lpSubKey, jint securityMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        HKEY handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        char* str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        int tmp[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        int errorCode=-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        jintArray result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    48
        CHECK_NULL_RETURN(str, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        errorCode =  RegOpenKeyEx((HKEY)hKey, str, 0, securityMask, &handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        tmp[0]= (int) handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        tmp[1]= errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        result = (*env)->NewIntArray(env,2);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    54
        if (result != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    55
            (*env)->SetIntArrayRegion(env, result, 0, 2, tmp);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    56
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegCloseKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
               (JNIEnv* env, jclass this_class, jint hKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return (jint) RegCloseKey((HKEY) hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegCreateKeyEx
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
               (JNIEnv* env, jclass this_class, jint hKey, jbyteArray lpSubKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        HKEY handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        char* str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        int tmp[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        DWORD lpdwDisposition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        int errorCode;
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    72
        jintArray result = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    74
        CHECK_NULL_RETURN(str, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        errorCode =  RegCreateKeyEx((HKEY)hKey, str, 0, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                      REG_OPTION_NON_VOLATILE, KEY_READ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                      NULL, &handle, &lpdwDisposition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        tmp[0]= (int) handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        tmp[1]= errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        tmp[2]= lpdwDisposition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        result = (*env)->NewIntArray(env,3);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    83
        if (result != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    84
            (*env)->SetIntArrayRegion(env, result, 0, 3, tmp);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    85
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
              (JNIEnv* env, jclass this_class, jint hKey, jbyteArray lpSubKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        char* str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        int result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
    94
        CHECK_NULL_RETURN(str, -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        result = RegDeleteKey((HKEY)hKey, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        (*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return  result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegFlushKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        (JNIEnv* env, jclass this_class, jint hKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return RegFlushKey ((HKEY)hKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    JNIEXPORT jbyteArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         (JNIEnv* env, jclass this_class, jint hKey, jbyteArray valueName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        char* valueNameStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        char* buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        jbyteArray result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        DWORD valueType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        DWORD valueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   114
        CHECK_NULL_RETURN(valueNameStr, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                 &valueSize) != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        buffer = (char*)malloc(valueSize);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   122
        if (buffer != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   123
            if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, buffer,
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   124
                &valueSize) != ERROR_SUCCESS) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   125
                free(buffer);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   126
                (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   127
                return NULL;
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   128
            }
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   129
        } else {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   130
            JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            (*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
   132
            return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (valueType == REG_SZ) {
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   136
            result = (*env)->NewByteArray(env, valueSize);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   137
            if (result != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   138
                (*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   139
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } else {
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   141
            result = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        free(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegSetValueEx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    (JNIEnv* env, jclass this_class, jint hKey, jbyteArray valueName, jbyteArray data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        char* valueNameStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        char* dataStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        int size = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        int nameSize = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        int error_code = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if ((valueName == NULL)||(data == NULL)) {return -1;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        size = (*env)->GetArrayLength(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        dataStr = (*env)->GetByteArrayElements(env, data, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   161
        CHECK_NULL_RETURN(dataStr, -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   163
        if (valueNameStr != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   164
            error_code = RegSetValueEx((HKEY)hKey, valueNameStr, 0,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                                        REG_SZ, dataStr, size);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   166
            (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   167
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        (*env)->ReleaseByteArrayElements(env, data, dataStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return error_code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            (JNIEnv* env, jclass this_class, jint hKey, jbyteArray valueName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        char* valueNameStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        int error_code = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (valueName == NULL) {return -1;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   178
        CHECK_NULL_RETURN(valueNameStr, -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        error_code = RegDeleteValue((HKEY)hKey, valueNameStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        (*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return error_code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                  (JNIEnv* env, jclass this_class, jint hKey) {
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   186
        jintArray result = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        int tmp[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        int valuesNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        int maxValueNameLength = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int maxSubKeyLength = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        int subKeysNumber = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        int errorCode = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        errorCode = RegQueryInfoKey((HKEY)hKey, NULL, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                 &subKeysNumber, &maxSubKeyLength, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                 &valuesNumber, &maxValueNameLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                 NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        tmp[0]= subKeysNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        tmp[1]= (int)errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        tmp[2]= valuesNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        tmp[3]= maxSubKeyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        tmp[4]= maxValueNameLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        result = (*env)->NewIntArray(env,5);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   203
        if (result != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   204
            (*env)->SetIntArrayRegion(env, result, 0, 5, tmp);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   205
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     JNIEXPORT jbyteArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegEnumKeyEx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     (JNIEnv* env, jclass this_class, jint hKey , jint subKeyIndex, jint maxKeyLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        int size = maxKeyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        jbyteArray result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        char* buffer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        buffer = (char*)malloc(maxKeyLength);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   215
        if (buffer == NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   216
            JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   217
            return NULL;
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   218
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                                 NULL, NULL) != ERROR_SUCCESS){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        free(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        result = (*env)->NewByteArray(env, size + 1);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   225
        if (result != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   226
            (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   227
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        free(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     JNIEXPORT jbyteArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegEnumValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
          (JNIEnv* env, jclass this_class, jint hKey , jint valueIndex, jint maxValueNameLength){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
          int size = maxValueNameLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
          jbyteArray result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
          char* buffer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
          int error_code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
          buffer = (char*)malloc(maxValueNameLength);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   239
          if (buffer == NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   240
              JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   241
              return NULL;
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   242
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
          error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                             &size, NULL, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
          if (error_code!= ERROR_SUCCESS){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            free(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
          result = (*env)->NewByteArray(env, size + 1);
23562
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   250
          if (result != NULL) {
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   251
              (*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
596efd9dfcaf 8035340: (prefs) Check jdk/src/windows/native/java/util/WindowsPreference.c for JNI pending exceptions
msheppar
parents: 22951
diff changeset
   252
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
          free(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
          return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
#ifdef __cplusplus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
#endif