harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r727327 - /harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
Date Wed, 17 Dec 2008 09:50:44 GMT
Author: lvjing
Date: Wed Dec 17 01:50:43 2008
New Revision: 727327

URL: http://svn.apache.org/viewvc?rev=727327&view=rev
Log:
Apply patch for HARMONY-6041, [classlib][portlib] incorrect parse path contains special unicode
charactor

Modified:
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c?rev=727327&r1=727326&r2=727327&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
Wed Dec 17 01:50:43 2008
@@ -405,6 +405,7 @@
 {
     int len;
     int wlen;
+    int absLen;
     char *canonicalpath;
     int srcArrayCount=0;
     int destArrayCount=0;
@@ -413,8 +414,10 @@
     int *slashStack; //record position of every separator.
     
     // Buffer to store absolute path name.
-    char absPath[ABS_PATH_BUF_LEN];
- 
+    wchar_t *absPath = 0;
+    wchar_t *temp = 0;
+    int i = 0;
+
     if (!path) {
         *pathW = (void*) 0;
         return;
@@ -428,15 +431,7 @@
         return;
     }
 
-    // calculate an absolute path first
-    if (!GetFullPathNameA(path, ABS_PATH_BUF_LEN, absPath, (void*) 0))
-    {
-        // error occurred
-        *pathW = (void*) 0;
-        return;
-    }
-
-    len = strlen(absPath);
+    len = strlen(path);
 
     slashStack = portLibrary->mem_allocate_memory(portLibrary, len*sizeof(int));
     canonicalpath = portLibrary->mem_allocate_memory(portLibrary, len+5);
@@ -445,15 +440,15 @@
 
     for(srcArrayCount=0,destArrayCount=4;srcArrayCount<len;srcArrayCount++){
         // we have an absolute path already.
-        if(absPath[srcArrayCount]=='.'){
+        if(path[srcArrayCount]=='.'){
             // count the dots following last separator.
-            if(dotsCount>0 || absPath[srcArrayCount-1]=='\\'){
+            if(dotsCount>0 || path[srcArrayCount-1]=='\\'){
                 dotsCount++;
                 continue;
             }
         }
         // deal with the dots when we meet next separator.
-        if(absPath[srcArrayCount]=='\\'){
+        if(path[srcArrayCount]=='\\'){
             if(dotsCount == 1){
                 dotsCount = 0;
                 continue;
@@ -476,17 +471,40 @@
             canonicalpath[destArrayCount++]='.';
             dotsCount--;
         }
-        canonicalpath[destArrayCount++]=absPath[srcArrayCount];
+        canonicalpath[destArrayCount++]=path[srcArrayCount];
     }
     while(canonicalpath[destArrayCount-1] == '.'){
         destArrayCount--;
     }        
     canonicalpath[destArrayCount]='\0';
+
     wlen = MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, 0);
     *pathW = portLibrary->mem_allocate_memory(portLibrary, wlen*sizeof(wchar_t));
     MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, wlen);
     portLibrary->mem_free_memory(portLibrary, canonicalpath);
     portLibrary->mem_free_memory(portLibrary, slashStack);
+
+    // calculate an absolute path
+    // call unicode version explicitly, should not include "\\?\" prefix
+    absLen = GetFullPathNameW(*pathW + 4, 0, absPath, (void*) 0);
+    absPath = portLibrary->mem_allocate_memory(portLibrary, (absLen + 4)*sizeof(wchar_t));
+    absLen = GetFullPathNameW(*pathW + 4, absLen, absPath + 4, (void*) 0);
+
+    if (absLen == 0)
+    {
+        // error occurred
+        *pathW = (void*) 0;
+        return;
+    }
+    // add prefix "\\?\"
+    for (i = 0; i < 4; ++i) {
+        absPath[i] = (*pathW)[i];
+    }
+
+    temp = *pathW;
+    *pathW = absPath;
+    absPath = temp;
+    portLibrary->mem_free_memory(portLibrary, absPath);
 }
 
 #undef ABS_PATH_BUF_LEN
@@ -508,7 +526,6 @@
 {
     int returnVar=0;
     wchar_t *pathW;
-
     convert_path_to_unicode(portLibrary, path, &pathW);
     returnVar = CreateDirectoryW (pathW, 0);
     portLibrary->mem_free_memory(portLibrary, pathW);



Mime
View raw message