commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r815199 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
Date Tue, 15 Sep 2009 07:53:33 GMT
Author: mturk
Date: Tue Sep 15 07:53:33 2009
New Revision: 815199

URL: http://svn.apache.org/viewvc?rev=815199&view=rev
Log:
Implement setting binary values as comma separated hexadecimal bytes

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c?rev=815199&r1=815198&r2=815199&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Tue Sep 15 07:53:33
2009
@@ -55,9 +55,9 @@
         sam |= KEY_READ;
     if (strchr(s, 'w'))
         sam |= KEY_WRITE;
-    if (strstr(s, "32"))
+    if (strchr(s, '3'))
         sam |= KEY_WOW64_32KEY;
-    else if (strstr(s, "64"))
+    else if (strchr(s, '6'))
         sam |= KEY_WOW64_64KEY;
     return sam;
 }
@@ -192,9 +192,10 @@
     INT64 qw;
     wchar_t *wn;
     char  tb[128];
-    unsigned char *buff  = NULL;
+    unsigned char *bb  = NULL;
     char          *value = NULL;
     wchar_t *wp;
+    wchar_t *wb;
     char    *cp;
 
     if (k && IS_INVALID_HANDLE(k->key)) {
@@ -209,34 +210,35 @@
                         &rt, NULL, &rl)) != ERROR_SUCCESS) {
         goto cleanup;
     }
-    buff = x_malloc((size_t)rl);
+    bb = x_malloc((size_t)rl);
     if ((rc = (int)RegQueryValueExW(k->key, wn, NULL,
-                        &rt, buff, &rl)) != ERROR_SUCCESS) {
+                        &rt, bb, &rl)) != ERROR_SUCCESS) {
         goto cleanup;
     }
+    wb = (wchar_t *)bb;
     switch (rt) {
         case REG_SZ:
-            value = x_strdup_utf8((wchar_t *)buff);
+            value = x_strdup_utf8(wb);
         break;
         case REG_MULTI_SZ:
-            for (wp = (wchar_t *)buff; *wp; wp++) {
+            for (wp = wb; *wp; wp++) {
                 while (*wp)
                     wp++;
                 if (*(wp + 1) != L'\0')
                     *wp = sc;
             }
-            value = x_strdup_utf8((wchar_t *)buff);
+            value = x_strdup_utf8(wb);
         break;
         case REG_EXPAND_SZ:
             {
                 wchar_t *sb;
                 DWORD    sz;
-                sz = ExpandEnvironmentStringsW((wchar_t *)buff, NULL, 0);
+                sz = ExpandEnvironmentStringsW(wb, NULL, 0);
                 if (sz) {
                     sb = x_malloc(sz * sizeof(wchar_t));
                     if (sb == NULL)
                         break;
-                    sz = ExpandEnvironmentStringsW((wchar_t *)buff, sb, sz);
+                    sz = ExpandEnvironmentStringsW(wb, sb, sz);
                     if (!sz) {
                         /* Shouldn't ever happen */
                         int rc = GetLastError();
@@ -249,20 +251,20 @@
             }
         break;
         case REG_DWORD:
-            memcpy(&rt, buff, 4);
+            memcpy(&rt, bb, 4);
             value = x_strdup(itoa(rt, tb, 10));
         break;
         case REG_QWORD:
-            memcpy(&qw, buff, 8);
+            memcpy(&qw, bb, 8);
             value = x_strdup(_i64toa(qw, tb, 10));
         break;
         case REG_BINARY:
             value = x_malloc(rl * 4 + 1);
             for (dw = 0, cp = value; dw < (rl - 1); dw++) {
-                sprintf(cp, "%02x, ", buff[dw]);
+                sprintf(cp, "%02x, ", bb[dw]);
                 cp += 4;
             }
-            sprintf(cp, "%02x", buff[dw]);
+            sprintf(cp, "%02x", bb[dw]);
         break;
         default:
             rc = ACR_EBADF;
@@ -271,7 +273,7 @@
 
 cleanup:
     x_free(wn);
-    x_free(buff);
+    x_free(bb);
     ACR_SET_OS_ERROR(rc);
     return value;
 }
@@ -284,7 +286,6 @@
     DWORD rl, dw;
     INT64 qw;
     wchar_t *wn;
-    unsigned char *buff = NULL;
     wchar_t *wp, *p;
 
     if (k && IS_INVALID_HANDLE(k->key)) {
@@ -336,7 +337,25 @@
                                 (const unsigned char *)&qw, 8);
         break;
         case REG_BINARY:
-            rc = ACR_ENOTIMPL;
+            {
+                DWORD i = 0;
+                const char *pp;
+                unsigned char *bb = x_malloc(strlen(value) / 2);
+                if (!bb) {
+                    rc = ACR_ENOMEM;
+                    break;
+                }
+                for (pp = value; *pp; ) {
+                    char *ep;
+                    unsigned long v = strtoul(pp, &ep, 16);
+
+                    bb[i++] = (unsigned char)v;
+                    pp = ep;
+                    while (*pp && !isxdigit((unsigned char)*pp))
+                        pp++;
+                }
+                rc = RegSetValueExW(k->key, wn, 0, st, bb, i);
+            }
         break;
         default:
             rc = ACR_EBADF;
@@ -345,6 +364,5 @@
 
 cleanup:
     x_free(wn);
-    x_free(buff);
     return rc;
 }



Mime
View raw message