commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r828321 - in /commons/sandbox/runtime/trunk/src/main/native/os/win32: dir.c file.c finfo.c fsysio.c
Date Thu, 22 Oct 2009 06:26:58 GMT
Author: mturk
Date: Thu Oct 22 06:26:57 2009
New Revision: 828321

URL: http://svn.apache.org/viewvc?rev=828321&view=rev
Log:
Always use path macros for ARC<->Win32 path conversion

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c?rev=828321&r1=828320&r2=828321&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c Thu Oct 22 06:26:57 2009
@@ -176,15 +176,6 @@
         return ACR_GET_OS_ERROR();
 }
 
-static __inline void FS2BS(wchar_t *path)
-{
-    while (*path) {
-        if (*path == L'/')
-            *path = L'\\';
-        path++;
-    }
-}
-
 static int _mkdir1(const wchar_t *name, int perms)
 {
     int rc;
@@ -197,7 +188,6 @@
         wchar_t *dir = ACR_StrdupW(INVALID_HANDLE_VALUE, THROW_NMARK, name);
         if (!dir)
             return ACR_ENOMEM;
-        FS2BS(dir);
         if ((pos = wcsrchr(dir, L'\\'))) {
             *pos = L'\0';
             if (*dir) {
@@ -214,9 +204,9 @@
 {
     int      rc = 0;
 
-    WITH_WSTR(name) {
+    WITH_WPATH(name) {
         rc = _mkdir0(J2W(name), perms);
-    } END_WITH_WSTR(name);
+    } END_WITH_WPATH(name);
     return rc;
 }
 
@@ -225,9 +215,9 @@
 {
     int      rc = 0;
 
-    WITH_WSTR(name) {
+    WITH_WPATH(name) {
         rc = _mkdir1(J2W(name), perms);
-    } END_WITH_WSTR(name);
+    } END_WITH_WPATH(name);
     return rc;
 }
 
@@ -239,16 +229,16 @@
 
     UNREFERENCED_O;
 
-    WITH_ZWSTR(path) {
-    WITH_ZWSTR(prefix) {
+    WITH_ZWPATH(path) {
+    WITH_ZWPATH(prefix) {
         /* Provide INVALID_HANDLE_VALUE for JNIEnv
          * so that in case of failure, exception doesn't get thrown
          */
         tmpd = ACR_TempDirMake(INVALID_HANDLE_VALUE, J2W(path), J2W(prefix));
         if (!tmpd)
             rc = ACR_GET_OS_ERROR();
-    } END_WITH_WSTR(prefix);
-    } END_WITH_WSTR(path);
+    } END_WITH_WPATH(prefix);
+    } END_WITH_WPATH(path);
     if (rc) {
         ACR_THROW_IO_IF_ERR(rc);
         return NULL;
@@ -267,9 +257,9 @@
 
     UNREFERENCED_O;
 
-    WITH_ZWSTR(paths) {
+    WITH_ZWPATH(paths) {
         tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2W(paths));
-    } END_WITH_WSTR(paths);
+    } END_WITH_WPATH(paths);
     if (tmpd)
         return ACR_NewJavaStringW(_E, tmpd);
     else

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=828321&r1=828320&r2=828321&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Thu Oct 22 06:26:57 2009
@@ -160,10 +160,9 @@
     int type = ACR_FT_UNKFILE;
 
     UNREFERENCED_O;
-    WITH_WSTR(pathname) {
-        FS2BS(J2W(pathname));
+    WITH_WPATH(pathname) {
         type = ACR_FileTypeGet(_E, J2W(pathname));
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
 
     return type;
 }
@@ -176,13 +175,12 @@
 
     UNREFERENCED_O;
 
-    WITH_WSTR(target) {
-    WITH_WSTR(lnkname) {
+    WITH_WPATH(target) {
+    WITH_WPATH(lnkname) {
         char  *mpb = NULL;
         DWORD  dwFlags = 0;
         size_t tlen = wcslen(J2W(target));
 
-        FS2BS(J2W(target));
         if (ACR_FileTypeGet(NULL, J2W(target)) == ACR_FT_DIR) {
             dwFlags = SYMBOLIC_LINK_FLAG_DIRECTORY;
         }
@@ -282,8 +280,8 @@
         }
 bailout:
         x_free(mpb);
-    } END_WITH_WSTR(lnkname);
-    } END_WITH_WSTR(target);
+    } END_WITH_WPATH(lnkname);
+    } END_WITH_WPATH(target);
 
     return rc;
 }
@@ -295,10 +293,8 @@
     jboolean rc = JNI_FALSE;
 
     UNREFERENCED_O;
-    WITH_WSTR(target) {
-    WITH_WSTR(lnkname) {
-        FS2BS(J2W(target));
-        FS2BS(J2W(lnkname));
+    WITH_WPATH(target) {
+    WITH_WPATH(lnkname) {
         if (!CreateHardLinkW(J2W(lnkname), J2W(target), NULL)) {
             int ex = ACR_GET_OS_ERROR();
             if (ACR_STATUS_IS_EACCES(ex)) {
@@ -310,8 +306,8 @@
         }
         else
             rc = JNI_TRUE;
-    } END_WITH_WSTR(lnkname);
-    } END_WITH_WSTR(target);
+    } END_WITH_WPATH(lnkname);
+    } END_WITH_WPATH(target);
 
     return rc;
 }
@@ -323,9 +319,8 @@
     int ex = 0;
 
     UNREFERENCED_O;
-    WITH_WSTR(lnkname) {
+    WITH_WPATH(lnkname) {
         void *buf = ACR_Calloc(_E, THROW_FMARK, MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
-        FS2BS(J2W(lnkname));
         if (buf) {
             HANDLE sh = CreateFileW(J2W(lnkname),
                                     GENERIC_READ,
@@ -337,6 +332,7 @@
             if (sh != INVALID_HANDLE_VALUE) {
                 DWORD dl;
                 PREPARSE_DATA_BUFFER repb;
+                wchar_t  ub[ACR_HBUFF_SIZ] = L"";
                 wchar_t *wb;
                 char    *pb;
                 size_t   noff;
@@ -360,8 +356,10 @@
                             nlen = repb->MountPointReparseBuffer.SubstituteNameLength;
                             noff = repb->MountPointReparseBuffer.SubstituteNameOffset;
                         }
-                        else
-                        rv = (*_E)->NewString(_E, (const jchar *)wb, (jsize)nlen);
+                        if (nlen > ACR_HBUFF_LEN)
+                            nlen = ACR_HBUFF_LEN;
+                        wcslcpy(ub, wb, nlen + 1);
+                        rv = acr_NewJavaNativePathW(_E, ub);
                     break;
                     case IO_REPARSE_TAG_SYMLINK:
                         pb   = (char *)repb->SymbolicLinkReparseBuffer.PathBuffer;
@@ -369,7 +367,8 @@
                         noff = repb->SymbolicLinkReparseBuffer.PrintNameOffset;
                         wb   = (wchar_t *)(pb + noff);
                         if (wimatch(wb, L"\\\\.\\PIPE\\*", NULL) == ACR_PMATCH_EXACT) {
-                            rv = (*_E)->NewString(_E, (const jchar *)wb, (jsize)nlen);
+                            wcslcpy(ub, wb, nlen + 1);
+                            rv = acr_NewJavaNativePathW(_E, ub);
                         }
                         else {
                             nlen = repb->SymbolicLinkReparseBuffer.SubstituteNameLength
/ sizeof(WCHAR);
@@ -384,7 +383,10 @@
                                     wb   += 2;
                                 }
                             }
-                            rv = (*_E)->NewString(_E, (const jchar *)wb, (jsize)nlen);
+                            if (nlen > ACR_HBUFF_LEN)
+                                nlen = ACR_HBUFF_LEN;
+                            wcslcpy(ub, wb, nlen + 1);
+                            rv = acr_NewJavaNativePathW(_E, ub);
                         }
                     break;
                     default:
@@ -399,7 +401,7 @@
             x_free(buf);
         }
 
-    } END_WITH_WSTR(lnkname);
+    } END_WITH_WPATH(lnkname);
 
     ACR_THROW_IO_IF_ERR(ex);
     return rv;
@@ -676,10 +678,9 @@
     int prot = 0;
 
     UNREFERENCED_O;
-    WITH_WSTR(pathname) {
-        FS2BS(J2W(pathname));
+    WITH_WPATH(pathname) {
         prot = ACR_FileProtectionGet(_E, J2W(pathname));
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
 
     return prot;
 }
@@ -691,10 +692,9 @@
 
     UNREFERENCED_O;
 
-    WITH_WSTR(pathname) {
-        FS2BS(J2W(pathname));
+    WITH_WPATH(pathname) {
         rc = ACR_FileProtectionSet(_E, J2W(pathname), prot);
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
 
     if (rc)
         return JNI_FALSE;
@@ -722,7 +722,7 @@
     }
 
 
-    WITH_WSTR(pathname) {
+    WITH_WPATH(pathname) {
         DWORD sec = 0;
         PSID susr = ACR_DescriptorGetPtr(_E, usr);
         PSID sgrp = ACR_DescriptorGetPtr(_E, grp);
@@ -731,7 +731,6 @@
             sec |= OWNER_SECURITY_INFORMATION;
         if (sgrp)
             sec |= GROUP_SECURITY_INFORMATION;
-        FS2BS(J2W(pathname));
         rc = SetNamedSecurityInfoW(J2W(pathname),
                                    SE_FILE_OBJECT,
                                    sec,
@@ -739,7 +738,7 @@
                                    sgrp,
                                    NULL,
                                    NULL);
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
     ACR_SetTokenPrivilege(L"SeTakeOwnershipPrivilege", FALSE);
     if (rc == ERROR_SUCCESS)
         return JNI_TRUE;
@@ -757,8 +756,7 @@
 
     UNREFERENCED_O;
 
-    WITH_WSTR(pathname) {
-        FS2BS(J2W(pathname));
+    WITH_WPATH(pathname) {
         flags = GetFileAttributesW(J2W(pathname));
         if (flags == INVALID_FILE_ATTRIBUTES)
             rc = GetLastError();
@@ -808,7 +806,7 @@
                     rc = GetLastError();
             }
         }
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
 
     if (rc == ERROR_SUCCESS)
         return JNI_TRUE;
@@ -824,15 +822,14 @@
     int   ex = ACR_EINVAL;
 
     UNREFERENCED_O;
-    WITH_WSTR(pathname) {
-        FS2BS(J2W(pathname));
+    WITH_WPATH(pathname) {
 
         rv = (jlong)ACR_FileInodeGet(NULL, J2W(pathname));
         if (rv == 0)
             ex = ACR_GET_OS_ERROR();
         else
             ex = 0;
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
 
     ACR_THROW_IO_IF_ERR(ex);
     return rv;
@@ -846,8 +843,7 @@
 
     UNREFERENCED_O;
 
-    WITH_WSTR(pathname) {
-        FS2BS(J2W(pathname));
+    WITH_WPATH(pathname) {
         flags = GetFileAttributesW(J2W(pathname));
         if (flags != INVALID_FILE_ATTRIBUTES) {
             if ((flags & FILE_ATTRIBUTE_HIDDEN))
@@ -869,7 +865,7 @@
         }
         else
             ex = ACR_GET_OS_ERROR();
-    } END_WITH_WSTR(pathname);
+    } END_WITH_WPATH(pathname);
 
     ACR_THROW_IO_IF_ERR(ex);
     return attr;
@@ -883,16 +879,16 @@
 
     UNREFERENCED_O;
 
-    WITH_ZWSTR(path) {
-    WITH_ZWSTR(prefix) {
+    WITH_ZWPATH(path) {
+    WITH_ZWPATH(prefix) {
         /* Provide INVALID_HANDLE_VALUE for JNIEnv
          * so that in case of failure, exception doesn't get thrown
          */
         tmpd = ACR_TempDirMake(INVALID_HANDLE_VALUE, J2W(path), J2W(prefix));
         if (!tmpd)
             rc = ACR_GET_OS_ERROR();
-    } END_WITH_WSTR(prefix);
-    } END_WITH_WSTR(path);
+    } END_WITH_WPATH(prefix);
+    } END_WITH_WPATH(path);
     if (rc) {
         ACR_THROW_IO_IF_ERR(rc);
         return NULL;
@@ -910,9 +906,9 @@
 
     UNREFERENCED_O;
 
-    WITH_ZWSTR(paths) {
+    WITH_ZWPATH(paths) {
         tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2W(paths));
-    } END_WITH_WSTR(paths);
+    } END_WITH_WPATH(paths);
     if (tmpd)
         return ACR_NewJavaStringW(_E, tmpd);
     else

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c?rev=828321&r1=828320&r2=828321&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c Thu Oct 22 06:26:57 2009
@@ -482,9 +482,9 @@
                                             jboolean full)
 {
     jobject fi = NULL;
-    WITH_WSTR(fname) {
+    WITH_WPATH(fname) {
         fi = _stat0(_E, J2W(fname), link, full);
-    } END_WITH_WSTR(fname);
+    } END_WITH_WPATH(fname);
 
     return fi;
 }
@@ -494,9 +494,9 @@
                                              jstring fname)
 {
     int rc = 0;
-    WITH_WSTR(fname) {
+    WITH_WPATH(fname) {
         rc = _stat2(_E, _O, J2W(fname));
-    } END_WITH_WSTR(fname);
+    } END_WITH_WPATH(fname);
 
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=828321&r1=828320&r2=828321&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Thu Oct 22 06:26:57 2009
@@ -281,9 +281,9 @@
     int rc = 0;
     jobject fdo = NULL;
 
-    WITH_WSTR(fname) {
+    WITH_WPATH(fname) {
         rc = do_fopen(_E, _O, J2W(fname), flags, ACR_FPROT_OS_DEFAULT, &fdo);
-    } END_WITH_WSTR(fname);
+    } END_WITH_WPATH(fname);
 
     if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
         /* Don't Throw in case of EXCL and EEXIST
@@ -304,9 +304,9 @@
     int rc = 0;
     jobject fdo = NULL;
 
-    WITH_WSTR(fname) {
+    WITH_WPATH(fname) {
         rc = do_fopen(_E, _O, J2W(fname), flags, prot, &fdo);
-    } END_WITH_WSTR(fname);
+    } END_WITH_WPATH(fname);
 
     if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
         /* Don't Throw in case of EXCL and EEXIST
@@ -403,7 +403,7 @@
     int ip = preserve == JNI_TRUE ? 1 : 0;
 
     WITH_WSTR(prefix) {
-        WITH_ZWSTR(path) {
+        WITH_ZWPATH(path) {
             WITH_ZWSTR(sufix) {
                 fo = ACR_TempFileMake(_E, J2W(path), J2W(prefix),
                                       J2W(sufix), ip);
@@ -421,7 +421,7 @@
                 else
                     rc = ACR_GET_OS_ERROR();
             } END_WITH_WSTR(sufix);
-        } END_WITH_WSTR(path);
+        } END_WITH_WPATH(path);
     } END_WITH_WSTR(prefix);
 
     if (rc) {



Mime
View raw message