https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c2a8984c7032de7a9335289cf7bec4bbbd0aaff8

commit c2a8984c7032de7a9335289cf7bec4bbbd0aaff8
Author:     Corinna Vinschen <cori...@vinschen.de>
AuthorDate: Thu Jul 17 13:36:42 2025 +0200
Commit:     Corinna Vinschen <cori...@vinschen.de>
CommitDate: Thu Jul 17 13:36:42 2025 +0200

    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 <cori...@vinschen.de>

Diff:
---
 winsup/cygwin/local_includes/registry.h |  2 ++
 winsup/cygwin/registry.cc               | 39 +++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/winsup/cygwin/local_includes/registry.h 
b/winsup/cygwin/local_includes/registry.h
index eed640401f18..87da9fed790e 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 273067143616..6b7f6e0695f1 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

Reply via email to