summaryrefslogtreecommitdiff
path: root/support/dktools/dk4wreg8.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/dk4wreg8.c
Initial commit
Diffstat (limited to 'support/dktools/dk4wreg8.c')
-rw-r--r--support/dktools/dk4wreg8.c459
1 files changed, 459 insertions, 0 deletions
diff --git a/support/dktools/dk4wreg8.c b/support/dktools/dk4wreg8.c
new file mode 100644
index 0000000000..6b4c7751bb
--- /dev/null
+++ b/support/dktools/dk4wreg8.c
@@ -0,0 +1,459 @@
+/*
+ WARNING: This file was generated by dkct.
+ Changes you make here will be lost if dkct is run again!
+ You should modify the original source and run dkct on it.
+ Original source: dk4wreg8.ctr
+*/
+
+/*
+Copyright (C) 2015-2017, Dirk Krause
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above opyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+* Neither the name of the author nor the names of contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/** @file dk4wreg8.c The dk4wreg8 module.
+*/
+
+
+#line 193 "dk4wreg8.ctr"
+
+#include "dk4conf.h"
+#include "dk4wregt.h"
+#include "dk4wreg8.h"
+#ifndef DK4MEM_H_INCLUDED
+#include "dk4mem.h"
+#endif
+#include "dk4maasz.h"
+
+#if DK4_ON_WINDOWS
+
+#ifndef WINDOWS_H_INCLUDED
+#include <windows.h>
+#define WINDOWS_H_INCLUDED 1
+#endif
+#ifndef WINBASE_H_INCLUDED
+#include <winbase.h>
+#define WINBASE_H_INCLUDED 1
+#endif
+#ifndef WINREG_H_INCLUDED
+#include <winreg.h>
+#define WINREG_H_INCLUDED 1
+#endif
+
+#endif
+
+#ifndef DK4STR8_H_INCLUDED
+#include "dk4str8.h"
+#endif
+
+
+
+
+
+#line 226 "dk4wreg8.ctr"
+
+
+
+void *
+dk4wreg_open_key_c8(int pk, const char *keyname, int wr, dk4_er_t *erp)
+{
+#if DK4_ON_WINDOWS
+ dk4_wreg_key_t *back = NULL;
+ HKEY park = HKEY_LOCAL_MACHINE;
+ LONG res;
+ DWORD disp;
+ if (NULL != keyname) {
+ switch (pk) {
+ case DK4_WREGKEY_HKLM:
+ case DK4_WREGKEY_HKCU:
+ case DK4_WREGKEY_HKCL:
+ case DK4_WREGKEY_KHUS:
+ case DK4_WREGKEY_HKCC: {
+ switch (pk) {
+ case DK4_WREGKEY_HKLM: {
+ park = HKEY_LOCAL_MACHINE;
+ } break;
+ case DK4_WREGKEY_HKCU: {
+ park = HKEY_CURRENT_USER;
+ } break;
+ case DK4_WREGKEY_HKCL: {
+ park = HKEY_CLASSES_ROOT;
+ } break;
+ case DK4_WREGKEY_KHUS: {
+ park = HKEY_USERS;
+ } break;
+ case DK4_WREGKEY_HKCC: {
+ park = HKEY_CURRENT_CONFIG;
+ } break;
+ }
+ back = dk4mem_new(dk4_wreg_key_t,1,erp);
+ if (NULL != back) {
+ res = RegCreateKeyExA(
+ park,
+ keyname,
+ (DWORD)0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ ((0 != wr) ? (KEY_ALL_ACCESS) : (KEY_READ)),
+ NULL,
+ &(back->hk),
+ &disp
+ );
+ if (ERROR_SUCCESS != res) {
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
+ dk4mem_free(back);
+ back = NULL;
+ }
+ }
+ } break;
+ default: {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ } break;
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return ((void *)back);
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+ return NULL;
+#endif
+}
+
+
+
+int
+dk4wreg_set_string_c8(
+ void *kptr, const char *name, const char *val, int expand, dk4_er_t *erp
+)
+{
+#if DK4_ON_WINDOWS
+ dk4_er_t er;
+ dk4_wreg_key_t *hptr;
+ int back = 0;
+ size_t lgt;
+ DWORD dwt = REG_SZ;
+ DWORD dw0 = (DWORD)0UL;
+ DWORD sz;
+ LONG res;
+ if ((NULL != kptr) && (NULL != val)) {
+ if (0 != expand) { dwt = REG_EXPAND_SZ; }
+ dk4error_init(&er);
+ lgt = dk4ma_size_t_add( 1, dk4str8_len(val), &er);
+ if (DK4_E_NONE == er.ec) {
+ if ((dk4_um_t)0x7FFFFFFFUL >= (dk4_um_t)lgt) {
+ sz = (DWORD)lgt;
+ hptr = (dk4_wreg_key_t *)kptr;
+ res = RegSetValueExA(
+ hptr->hk,
+ name,
+ dw0,
+ dwt,
+ (const BYTE *)val,
+ sz
+ );
+ if (ERROR_SUCCESS == res) {
+ back = 1;
+ } else {
+ dk4error_set_ldetails(erp, DK4_E_SYSTEM, res);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+ return 0;
+#endif
+}
+
+
+
+int
+dk4wreg_get_string_c8(
+ void *kptr,
+ const char *name,
+ char *bptr,
+ size_t sz,
+ int *expand,
+ dk4_er_t *erp
+)
+{
+#if DK4_ON_WINDOWS
+ dk4_wreg_key_t *hptr;
+ int back = 0;
+ DWORD dwt = REG_SZ;
+ DWORD dws;
+ DWORD dwsbck;
+ LONG res;
+ if ((NULL != bptr) && (0 < sz)) {
+ *bptr = '\0';
+ }
+ if ((NULL != kptr) && (NULL != name) && (NULL != bptr) && (0 < sz)) {
+ if ((dk4_um_t)0x7FFFFFFFUL >= (dk4_um_t)sz) {
+ dws = (DWORD)sz;
+ } else {
+ dws = (DWORD)0x7FFFFFFFUL;
+ }
+ dwsbck = dws;
+ hptr = (dk4_wreg_key_t *)kptr;
+ res = RegQueryValueExA(
+ hptr->hk,
+ name,
+ NULL,
+ &dwt,
+ (LPBYTE)bptr,
+ &dws
+ );
+ if (ERROR_SUCCESS == res) {
+ switch (dwt) {
+ case REG_SZ: case REG_EXPAND_SZ: {
+ if ((DWORD)0L < dws) {
+ if (dws < dwsbck) { /* dws is positive */
+ bptr[dws] = '\0';
+ } else {
+ bptr[dwsbck-1] = '\0';
+ }
+ back = 1;
+ if (REG_EXPAND_SZ == dwt) {
+ if (NULL != expand) {
+ *expand = 1;
+ }
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
+ }
+ } break;
+ default: {
+ /* ERROR: Not a string */
+ dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
+ } break;
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+ return 0;
+#endif
+}
+
+
+
+int
+dk4wreg_set_dword_c8(
+ void *kptr, const char *name, dk4_dword_t val, dk4_er_t *erp
+)
+{
+#if DK4_ON_WINDOWS
+ dk4_wreg_key_t *hptr;
+ int back = 0;
+ DWORD dwt = REG_DWORD;
+ DWORD dws = sizeof(DWORD);
+ DWORD dw0 = (DWORD)0L;
+ LONG res;
+ if (NULL != kptr) {
+ hptr = (dk4_wreg_key_t *)kptr;
+ res = RegSetValueExA(
+ hptr->hk,
+ name,
+ dw0,
+ dwt,
+ (const BYTE *)(&val),
+ dws
+ );
+ if (ERROR_SUCCESS == res) {
+ back = 1;
+ } else {
+ dk4error_set_ldetails(erp, DK4_E_SYSTEM, res);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+ return 0;
+#endif
+}
+
+
+
+int
+dk4wreg_get_dword_c8(
+ void *kptr,
+ const char *name,
+ dk4_dword_t *vptr,
+ dk4_er_t *erp
+)
+{
+#if DK4_ON_WINDOWS
+ dk4_wreg_key_t *hptr;
+ int back = 0;
+ DWORD dwt = REG_DWORD;
+ DWORD dws = (DWORD)sizeof(DWORD);
+ LONG res;
+ if ((NULL != kptr) && (NULL != vptr)) {
+ hptr = (dk4_wreg_key_t *)kptr;
+ res = RegQueryValueExA(
+ hptr->hk,
+ name,
+ NULL,
+ &dwt,
+ (LPBYTE)vptr,
+ &dws
+ );
+ if (ERROR_SUCCESS == res) {
+ if (REG_DWORD == dwt) {
+ if ((DWORD)sizeof(DWORD) == dws) {
+ back = 1;
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
+ }
+ } else {
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ return back;
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+ return 0;
+#endif
+}
+
+
+
+int
+dk4wreg_get_expanded_string_c8(
+ void *kptr,
+ const char *name,
+ char *dptr,
+ size_t dsz,
+ char *b1,
+ size_t b1sz,
+ char *b2,
+ size_t b2sz,
+ dk4_er_t *erp
+)
+{
+#if DK4_ON_WINDOWS
+ DWORD nc;
+ DWORD dws;
+ int expand = 0;
+ int back = 0;
+
+
+#line 532 "dk4wreg8.ctr"
+ if ((NULL != dptr) && (0 < dsz)) { *dptr = '\0'; }
+ if ((NULL != kptr) && (NULL != name) && (NULL != dptr) && (0 < dsz)) {
+ if ((NULL != b1) && (NULL != b2) && (0 < b1sz) && (2 < b2sz)) {
+ back = dk4wreg_get_string_c8(kptr, name, b1, b1sz, &expand, erp);
+ if (0 != back) {
+
+#line 537 "dk4wreg8.ctr"
+ if (0 != expand) {
+
+#line 538 "dk4wreg8.ctr"
+ if ((dk4_um_t)(0x7FFFFFFFUL) >= (dk4_um_t)b2sz) {
+ dws = (DWORD)b2sz;
+
+#line 540 "dk4wreg8.ctr"
+ } else {
+ dws = 0x7FFFFFFFUL;
+
+#line 542 "dk4wreg8.ctr"
+ }
+ dws = dws - 2;
+ nc = ExpandEnvironmentStringsA(b1, b2, dws);
+ if ((0 < nc) && (nc <= dws)) {
+
+#line 546 "dk4wreg8.ctr"
+ back = dk4str8_cpy_s(dptr, dsz, b2, erp);
+
+
+#line 548 "dk4wreg8.ctr"
+
+
+#line 549 "dk4wreg8.ctr"
+
+
+#line 550 "dk4wreg8.ctr"
+ } else {
+
+#line 551 "dk4wreg8.ctr"
+ dk4error_set_simple_error_code(erp, DK4_E_BUFFER_TOO_SMALL);
+ }
+ } else {
+
+#line 554 "dk4wreg8.ctr"
+ back = dk4str8_cpy_s(dptr, dsz, b1, erp);
+
+
+#line 556 "dk4wreg8.ctr"
+
+
+#line 557 "dk4wreg8.ctr"
+
+
+#line 558 "dk4wreg8.ctr"
+ }
+ } else {
+
+#line 560 "dk4wreg8.ctr"
+ }
+ } else {
+
+#line 562 "dk4wreg8.ctr"
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+ } else {
+
+#line 565 "dk4wreg8.ctr"
+ dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
+ }
+
+#line 567 "dk4wreg8.ctr"
+ return back;
+#else
+ dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
+ return 0;
+#endif
+}
+