diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2025-07-17 13:36:42 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2025-07-17 13:36:42 +0200 |
commit | c2a8984c7032de7a9335289cf7bec4bbbd0aaff8 (patch) | |
tree | 2e9d667baeef8fc017fc21719bba6f28899d28fa | |
parent | 49ba5f467c4278be04274c96d799943830d5f6d3 (diff) | |
download | newlib-c2a8984c7032de7a9335289cf7bec4bbbd0aaff8.zip newlib-c2a8984c7032de7a9335289cf7bec4bbbd0aaff8.tar.gz newlib-c2a8984c7032de7a9335289cf7bec4bbbd0aaff8.tar.bz2 |
Cygwin: reg_key: add a method get_binary() to fetch REG_BINARY data
This patch is required for a followup patch fetching the leap seconds
info from the registry starting with Windows 10 1803.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r-- | winsup/cygwin/local_includes/registry.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/registry.cc | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/winsup/cygwin/local_includes/registry.h b/winsup/cygwin/local_includes/registry.h index eed6404..87da9fe 100644 --- a/winsup/cygwin/local_includes/registry.h +++ b/winsup/cygwin/local_includes/registry.h @@ -30,6 +30,8 @@ public: NTSTATUS set_dword (PCWSTR, DWORD); NTSTATUS set_string (PCWSTR, PCWSTR); + NTSTATUS get_binary (PCWSTR, void *, size_t, size_t &); + bool created () const {return _disposition & REG_CREATED_NEW_KEY;} ~reg_key (); diff --git a/winsup/cygwin/registry.cc b/winsup/cygwin/registry.cc index 2730671..6b7f6e0 100644 --- a/winsup/cygwin/registry.cc +++ b/winsup/cygwin/registry.cc @@ -189,6 +189,45 @@ reg_key::get_string (PCWSTR name, PWCHAR dst, size_t max, PCWSTR def) return status; } +/* Given the current registry key, return the specific binary value + requested. Return zero on success, non-zero on failure. + + max is the size of the incoming buffer. + The actual size of the binary data read from the registry is returned + in size_ret. */ + +NTSTATUS +reg_key::get_binary (PCWSTR name, void *dst, size_t max, size_t &size_ret) +{ + NTSTATUS status; + + if (key_is_invalid) + { + status = key_is_invalid; + size_ret = 0; + } + else + { + UNICODE_STRING uname; + ULONG size = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + max * sizeof (WCHAR); + ULONG rsize; + PKEY_VALUE_PARTIAL_INFORMATION vbuf = (PKEY_VALUE_PARTIAL_INFORMATION) + alloca (size); + + RtlInitUnicodeString (&uname, name); + status = NtQueryValueKey (key, &uname, KeyValuePartialInformation, vbuf, + size, &rsize); + if (status != STATUS_SUCCESS || vbuf->Type != REG_BINARY) + size_ret = 0; + else + { + size_ret = MIN (max, vbuf->DataLength); + memcpy (dst, vbuf->Data, size_ret); + } + } + return status; +} + /* Given the current registry key, set a specific string value. */ NTSTATUS |