commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r828077 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
Date Wed, 21 Oct 2009 16:10:58 GMT
Author: mturk
Date: Wed Oct 21 16:10:58 2009
New Revision: 828077

URL: http://svn.apache.org/viewvc?rev=828077&view=rev
Log:
Add counterpart acr path function

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

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=828077&r1=828076&r2=828077&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Wed Oct 21 16:10:58 2009
@@ -197,8 +197,8 @@
         if (srcstr[4] == L'U' && srcstr[5] == L'N' &&
             srcstr[6] == L'C' && srcstr[7] == L'\\') {
             srcstr += 8;
-            retstr[0] = '\\';
-            retstr[1] = '\\';
+            retstr[0] = '/';
+            retstr[1] = '/';
             retlen -= 2;
             retstr += 2;
         }
@@ -220,8 +220,47 @@
     return 0;
 }
 
-static int acr_to_unicode_path(wchar_t* retstr, size_t retlen,
-                               const wchar_t* srcstr)
+int unicode_to_acr_path(wchar_t* retstr, size_t retlen,
+                        const wchar_t* srcstr)
+{
+    size_t len;
+    /* Skip the leading 4 characters if the path begins \\?\, or substitute
+     * // for the \\?\UNC\ path prefix, allocating the maximum string
+     * length based on the remaining string, plus the trailing null.
+     * then transform \\'s back into /'s since the \\?\ form never
+     * allows '/' path seperators, and APR always uses '/'s.
+     */
+    if (srcstr[0] == L'\\' && srcstr[1] == L'\\' &&
+        srcstr[2] == L'?'  && srcstr[3] == L'\\') {
+        if (srcstr[4] == L'U' && srcstr[5] == L'N' &&
+            srcstr[6] == L'C' && srcstr[7] == L'\\') {
+            srcstr += 8;
+            retstr[0] = L'/';
+            retstr[1] = L'/';
+            retlen -= 2;
+            retstr += 2;
+        }
+        else {
+            srcstr += 4;
+        }
+    }
+    len = wcslen(srcstr);
+    if (len > retlen)
+        return ACR_EOVERFLOW;
+    memcpy(retstr, srcstr, (len + 1) * sizeof(wchar_t));
+    /* Translate all back to forward slashes.
+     * On Win32 for utf8 paths we always use the forward slashes.
+     * They are converted to backward on translation from acr.
+     */
+    for (; *retstr; retstr++) {
+        if (*retstr == '\\')
+            *retstr = '/';
+    }
+    return 0;
+}
+
+int acr_to_unicode_path(wchar_t* retstr, size_t retlen,
+                        const wchar_t* srcstr)
 {
     /* TODO: The computations could preconvert the string to determine
      * the true size of the retstr, but that's a memory over speed
@@ -300,8 +339,7 @@
     }
     if (srclen > retlen)
         return ACR_EOVERFLOW;
-    memcpy(t, srcstr, srclen * sizeof(wchar_t));
-    t[srclen] = L'\0';
+    memcpy(t, srcstr, (srclen + 1) * sizeof(wchar_t));
     for (; *t; t++) {
         if (*t == L'/')
             *t = L'\\';



Mime
View raw message