commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r810389 - in /commons/sandbox/runtime/trunk/src/main/native: include/arch/windows/acr_arch_private.h os/win32/env.c os/win32/temps.c
Date Wed, 02 Sep 2009 07:24:58 GMT
Author: mturk
Date: Wed Sep  2 07:24:58 2009
New Revision: 810389

URL: http://svn.apache.org/viewvc?rev=810389&view=rev
Log:
Add private wide char version of envvar functions

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/env.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=810389&r1=810388&r2=810389&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Wed Sep  2 07:24:58 2009
@@ -120,7 +120,7 @@
 #define ACR_HeapFree(M)     HeapFree(dll_heap_handle, 0, (M))
 
 /**
- * Utility functions from wutilc.
+ * Utility functions from wutil.c
  */
 wchar_t *res_name_from_filenamew(int, wchar_t *, const wchar_t *);
 int      utf8_to_unicode_path(wchar_t *, size_t, const char *);
@@ -128,6 +128,12 @@
 wchar_t *x_wcsdup_utf8(const char *);
 char    *x_strdup_utf8(const wchar_t *);
 
+/**
+ * Wide char envvar functions from env.c
+ */
+wchar_t *acr_EnvGetW(const wchar_t *);
+int      acr_EnvSetW(const wchar_t *, const wchar_t *);
+int      acr_EnvDeleteW(const wchar_t *);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/env.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/env.c?rev=810389&r1=810388&r2=810389&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/env.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/env.c Wed Sep  2 07:24:58 2009
@@ -177,3 +177,72 @@
     return 0;
 }
 
+wchar_t *acr_EnvGetW(const wchar_t *var)
+{
+    return _wgetenv(var);
+}
+
+int acr_EnvSetW(const wchar_t *var, const wchar_t *val)
+{
+    wchar_t *estr;
+    size_t   elen;
+
+    if (!var || !*var || !val) {
+        errno = EINVAL;
+        return -1;
+    }
+    elen = (wcslen(var) + wcslen(val) + 2) * sizeof(wchar_t);
+    estr = (wchar_t *)malloc(elen);
+    if (!estr)                /* not much we can do if no memory */
+        return -1;
+
+    /* Override the existing setting by forcibly defining the var */
+#if _MSC_VER >= 1300
+    swprintf(estr, elen, L"%s=%s", var, val);
+#else
+    swprintf(estr,       L"%s=%s", var, val);
+#endif
+    if (_msvcrt_wputenv(estr)) {
+        int se = errno;
+        free(estr);
+        errno = se;
+        return -1;
+    }
+
+    free(estr);
+    return 0;
+}
+
+int acr_EnvDeleteW(const wchar_t *var)
+{
+    wchar_t *estr;
+    size_t   elen;
+
+    if (!var || !*var) {
+        errno = EINVAL;
+        return -1;
+    }
+    if (_wgetenv(var) == NULL)
+        return 0;             /* no work */
+    elen = (wcslen(var) + 2) * sizeof(wchar_t);
+    estr = (wchar_t *)malloc(elen);
+    if (!estr)                /* not much we can do if no memory */
+        return -1;
+
+    /* Override the existing setting by forcibly defining the var */
+#if _MSC_VER >= 1300
+    swprintf(estr, elen, L"%s=", var);
+#else
+    swprintf(estr,       L"%s=", var);
+#endif
+    if (_msvcrt_wputenv(estr)) {
+        int se = errno;
+        free(estr);
+        errno = se;
+        return -1;
+    }
+
+    free(estr);
+    return 0;
+}
+

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c?rev=810389&r1=810388&r2=810389&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/temps.c Wed Sep  2 07:24:58 2009
@@ -261,7 +261,7 @@
     if (_temp_path[0])
         return _temp_path;
     while (_try_envs[i]) {
-        wchar_t *val = _wgetenv(_try_envs[i]);
+        wchar_t *val = acr_EnvGetW(_try_envs[i]);
         if (val && *val) {
             if (wcslen(val) < TMP_PATH_MAX) {
                 if (_temp_test(val)) {
@@ -288,7 +288,7 @@
     }
     else {
         /* Finally try the users %USERPROFILE% */
-        wchar_t *val = _wgetenv(L"USERPROFILE");
+        wchar_t *val = acr_EnvGetW(L"USERPROFILE");
         if (val && *val) {
             if (wcslen(val) < TMP_PATH_MAX) {
                 if (_temp_test(val))



Mime
View raw message