<commit_before>#ifdef WIN32
#define UNICODE
#define _UNICODE

#include <stdlib.h>

#include "win32bindings.h"
#include "javasigar.h"

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jint JNICALL SIGAR_JNI(win32_RegistryKey_RegCloseKey)
(JNIEnv *, jclass, jlong hkey)
{
    return RegCloseKey((HKEY)hkey);
}

JNIEXPORT jlong JNICALL SIGAR_JNI(win32_RegistryKey_RegCreateKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey)
{
    HKEY    hkeyResult = NULL;
    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    
    RegCreateKeyEx((HKEY)hkey, lpSubkey, 0, NULL, 
                   REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 
                   NULL, &hkeyResult, NULL);

    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);

    return (jlong)hkeyResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegDeleteKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey)
{
    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    LONG    lResult  = RegDeleteKey((HKEY)hkey, lpSubkey);
    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);

    return lResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegDeleteValue)
(JNIEnv *env, jclass, jlong hkey, jstring valueName)
{
    LPCTSTR lpValueName = (LPCTSTR)env->GetStringChars(valueName, NULL);
    LONG    lResult     = RegDeleteValue((HKEY)hkey, lpValueName);
    env->ReleaseStringChars(valueName, (const jchar *)lpValueName);

    return lResult;
}

JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegEnumKey)
(JNIEnv *env, jclass, jlong hkey, jint index)
{
    jstring strResult;
    TCHAR   szBuffer[MAX_PATH + 1];

    if(RegEnumKey((HKEY)hkey, index, szBuffer, 
                  sizeof(szBuffer)) == ERROR_SUCCESS)
        strResult = env->NewString((const jchar *)szBuffer, 
                                   lstrlen(szBuffer));
    else
        strResult = NULL;

    return strResult;
}

JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegEnumValueName)
(JNIEnv *env, jclass, jlong hkey, jint index)
{
    jstring strResult;
    TCHAR   szValueName[MAX_PATH + 1];
    DWORD   cbValueName = sizeof(szValueName);

    if(RegEnumValue((HKEY)hkey, index, szValueName, 
                    &cbValueName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
        strResult = env->NewString((const jchar *)szValueName, 
                                   lstrlen(szValueName));
    else
        strResult = NULL;

    return strResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegFlushKey)
(JNIEnv *env, jclass, long hkey)
{
    return RegFlushKey((HKEY)hkey);
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegLoadKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey, jstring file)
{
    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    LPCTSTR lpFile   = (LPCTSTR)env->GetStringChars(file, NULL);

    LONG lResult = RegLoadKey((HKEY)hkey, lpSubkey, lpFile);

    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);
    env->ReleaseStringChars(file, (const jchar *)lpFile);

    return lResult;
}

JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey)
{
    HKEY    hkeyResult = NULL;

    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    RegOpenKey((HKEY)hkey, lpSubkey, &hkeyResult);
    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);

    return (jlong)hkeyResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegQueryIntValue)
(JNIEnv *env, jclass, jlong hkey, jstring valueName)
{
    DWORD   dwResult;
    DWORD   dwType;<commit_msg>fix bug under websphere4.0 jdk, key was not always null terminated<commit_after>#ifdef WIN32
#define UNICODE
#define _UNICODE

#include <stdlib.h>

#include "win32bindings.h"
#include "javasigar.h"

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jint JNICALL SIGAR_JNI(win32_RegistryKey_RegCloseKey)
(JNIEnv *, jclass, jlong hkey)
{
    return RegCloseKey((HKEY)hkey);
}

JNIEXPORT jlong JNICALL SIGAR_JNI(win32_RegistryKey_RegCreateKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey)
{
    HKEY    hkeyResult = NULL;
    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    
    RegCreateKeyEx((HKEY)hkey, lpSubkey, 0, NULL, 
                   REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 
                   NULL, &hkeyResult, NULL);

    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);

    return (jlong)hkeyResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegDeleteKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey)
{
    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    LONG    lResult  = RegDeleteKey((HKEY)hkey, lpSubkey);
    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);

    return lResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegDeleteValue)
(JNIEnv *env, jclass, jlong hkey, jstring valueName)
{
    LPCTSTR lpValueName = (LPCTSTR)env->GetStringChars(valueName, NULL);
    LONG    lResult     = RegDeleteValue((HKEY)hkey, lpValueName);
    env->ReleaseStringChars(valueName, (const jchar *)lpValueName);

    return lResult;
}

JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegEnumKey)
(JNIEnv *env, jclass, jlong hkey, jint index)
{
    jstring strResult;
    TCHAR   szBuffer[MAX_PATH + 1];

    if(RegEnumKey((HKEY)hkey, index, szBuffer, 
                  sizeof(szBuffer)) == ERROR_SUCCESS)
        strResult = env->NewString((const jchar *)szBuffer, 
                                   lstrlen(szBuffer));
    else
        strResult = NULL;

    return strResult;
}

JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegEnumValueName)
(JNIEnv *env, jclass, jlong hkey, jint index)
{
    jstring strResult;
    TCHAR   szValueName[MAX_PATH + 1];
    DWORD   cbValueName = sizeof(szValueName);

    if(RegEnumValue((HKEY)hkey, index, szValueName, 
                    &cbValueName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
        strResult = env->NewString((const jchar *)szValueName, 
                                   lstrlen(szValueName));
    else
        strResult = NULL;

    return strResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegFlushKey)
(JNIEnv *env, jclass, long hkey)
{
    return RegFlushKey((HKEY)hkey);
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegLoadKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey, jstring file)
{
    LPCTSTR lpSubkey = (LPCTSTR)env->GetStringChars(subkey, NULL);
    LPCTSTR lpFile   = (LPCTSTR)env->GetStringChars(file, NULL);

    LONG lResult = RegLoadKey((HKEY)hkey, lpSubkey, lpFile);

    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);
    env->ReleaseStringChars(file, (const jchar *)lpFile);

    return lResult;
}

JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey)
(JNIEnv *env, jclass, jlong hkey, jstring subkey)
{
    HKEY    hkeyResult = NULL;
    jsize len = env->GetStringLength(subkey);
    LPTSTR lpSubkey = (LPTSTR)env->GetStringChars(subkey, NULL);
    char orig = lpSubkey[len];
    /* required under IBM/WebSphere 4.0 for certain keys */
    lpSubkey[len] = '\0';
    RegOpenKey((HKEY)hkey, lpSubkey, &hkeyResult);
    lpSubkey[len] = orig;
    env->ReleaseStringChars(subkey, (const jchar *)lpSubkey);

    return (jlong)hkeyResult;
}

JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegQueryIntValue)
(JNIEnv *env, jclass, jlong hkey, jstring valueName)
{
    DWORD   dwResult;
    DWORD   dwType;
{'fraction_non_alphanumeric': 0.10522724170874846, 'fraction_numerical': 0.008052408898594241, 'mean_word_length': 3.9049531459170015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1777956', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2645, 'n_words': 546}