commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r805031 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
Date Mon, 17 Aug 2009 16:31:47 GMT
Author: mturk
Date: Mon Aug 17 16:31:46 2009
New Revision: 805031

URL: http://svn.apache.org/viewvc?rev=805031&view=rev
Log:
We'll use inode for readdir as well

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

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=805031&r1=805030&r2=805031&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 Mon Aug 17 16:31:46 2009
@@ -53,10 +53,10 @@
 
 static __inline void FS2BS(wchar_t *path)
 {
-    size_t i;
-    for (i = 0; i < wcslen(path); i++) {
-        if (path[i] == L'/')
-            path[i] = L'\\';
+    while (*path) {
+        if (*path == L'/')
+            *path = L'\\';
+        path++;
     }
 }
 
@@ -121,6 +121,41 @@
     return -1;
 }
 
+ACR_DECLARE(acr_uint64_t) ACR_FileInodeGet(JNIEnv *_E, const wchar_t *fname)
+{
+    HANDLE fh;
+    acr_uint64_t rv = 0;
+    int ex = 0;
+
+    fh = CreateFileW(fname,
+                     0, /* Query attributes without accessing the file */
+                     FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                     NULL,
+                     OPEN_EXISTING,
+                     FILE_FLAG_BACKUP_SEMANTICS,
+                     NULL);
+    if (fh != INVALID_HANDLE_VALUE) {
+        BY_HANDLE_FILE_INFORMATION fi;
+        if (GetFileInformationByHandle(fh, &fi)) {
+            rv = (((acr_uint64_t)fi.nFileIndexHigh + (acr_uint64_t)fi.dwVolumeSerialNumber)
<< 30) + fi.nFileIndexLow;
+            ex = 0;
+        }
+        else
+            ex = ACR_GET_OS_ERROR();
+        CloseHandle(fh);
+    }
+    else
+        ex = ACR_GET_OS_ERROR();
+    if (ex) {
+        rv = 0;
+        ACR_SET_OS_ERROR(ex);
+        if (!IS_INVALID_HANDLE(_E))
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
+    }
+    return rv;
+}
+
+
 ACR_IO_EXPORT_DECLARE(int, File, ftype0)(ACR_JNISTDARGS, jstring pathname)
 {
     int type = ACR_FT_UNKFILE;
@@ -660,7 +695,7 @@
 ACR_IO_EXPORT_DECLARE(jboolean, File, fprot2)(ACR_JNISTDARGS, jstring pathname,
                                               jobject usr, jobject grp)
 {
-    int rc = EINVAL;
+    int rc = ACR_EINVAL;
 
     UNREFERENCED_O;
 
@@ -711,7 +746,7 @@
 ACR_IO_EXPORT_DECLARE(jboolean, File, attrs0)(ACR_JNISTDARGS, jstring pathname,
                                               jint attr, jint mask)
 {
-    int rc = EINVAL;
+    int rc = ACR_EINVAL;
     DWORD flags;
 
     UNREFERENCED_O;
@@ -784,31 +819,14 @@
 ACR_IO_EXPORT_DECLARE(jlong, File, inode0)(ACR_JNISTDARGS, jstring pathname)
 {
     jlong rv = 0;
-    int   ex = EINVAL;
+    int   ex = ACR_EINVAL;
 
     UNREFERENCED_O;
     WITH_WSTR(pathname) {
-        HANDLE fh;
         FS2BS(J2W(pathname));
 
-        fh = CreateFileW(J2W(pathname),
-                         0, /* Query attributes without accessing the file */
-                         FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
-                         NULL,
-                         OPEN_EXISTING,
-                         FILE_FLAG_BACKUP_SEMANTICS,
-                         NULL);
-        if (fh != INVALID_HANDLE_VALUE) {
-            BY_HANDLE_FILE_INFORMATION fi;
-            if (GetFileInformationByHandle(fh, &fi)) {
-                rv = (((jlong)fi.nFileIndexHigh + (jlong)fi.dwVolumeSerialNumber) <<
30) + fi.nFileIndexLow;
-                ex = 0;
-            }
-            else
-                ex = ACR_GET_OS_ERROR();
-            CloseHandle(fh);
-        }
-        else
+        rv = (jlong)ACR_FileInodeGet(NULL, J2W(pathname));
+        if (rv == 0)
             ex = ACR_GET_OS_ERROR();
     } END_WITH_WSTR(pathname);
 



Mime
View raw message