aboutsummaryrefslogtreecommitdiffstats
path: root/common/w32-reg.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/w32-reg.c')
-rw-r--r--common/w32-reg.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/common/w32-reg.c b/common/w32-reg.c
index d8d94b90e..f36c66453 100644
--- a/common/w32-reg.c
+++ b/common/w32-reg.c
@@ -226,5 +226,53 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
#endif /*!HAVE_W32CE_SYSTEM*/
}
+/* Compact version of read_w32_registry_string. This version expects
+ * a single string as key described here using an example:
+ *
+ * HKCU\Software\GNU\GnuPG:HomeDir
+ *
+ * HKCU := the class, other supported classes are HKLM, HKCR, HKU, and
+ * HKCC. If no class is given and the string thus starts with
+ * a backslash HKCU with a fallback to HKLM is used.
+ * Software\GNU\GnuPG := The actual key.
+ * HomeDir := the name of the item. The name is optional to use the default
+ * value.
+ *
+ * Note that the first backslash and the first colon act as delimiters.
+ *
+ * Returns a malloced string or NULL if not found.
+ */
+char *
+read_w32_reg_string (const char *key_arg)
+{
+ char *key;
+ char *p1, *p2;
+ char *result;
+
+ if (!key_arg)
+ return NULL;
+ key = xtrystrdup (key_arg);
+ if (!key)
+ {
+ log_info ("warning: malloc failed while reading registry key\n");
+ return NULL;
+ }
+
+ p1 = strchr (key, '\\');
+ if (!p1)
+ {
+ xfree (key);
+ return NULL;
+ }
+ *p1++ = 0;
+ p2 = strchr (p1, ':');
+ if (p2)
+ *p2++ = 0;
+
+ result = read_w32_registry_string (*key? key : NULL, p1, p2);
+ xfree (key);
+ return result;
+}
+
#endif /*HAVE_W32_SYSTEM*/