BugZilla 25140, 5451. multi-byte char-set handling. Big file handling on NT NSPRPUB_RELEASE_4_0_BRANCH
authorlarryh%netscape.com
Wed, 26 Jan 2000 23:54:05 +0000
branchNSPRPUB_RELEASE_4_0_BRANCH
changeset 1100 c360b5ce32145c1c39cb3db415d25d0145d68d70
parent 1099 e383e69269014ca7621a83150884efea602feeac
child 1101 d7c48a690c408cbda06354a405225fbfce294083
push idunknown
push userunknown
push dateunknown
bugs25140
BugZilla 25140, 5451. multi-byte char-set handling. Big file handling on NT
pr/src/md/windows/ntio.c
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -32,16 +32,17 @@
  * be incorrectly completed on the GLOBAL_SCOPE IO thread; this will mean
  * extra context switching; but I don't think there is anything I can do
  * about it.
  */
 
 #include "primpl.h"
 #include "pprmwait.h"
 #include <direct.h>
+#include <mbstring.h>
 
 static HANDLE                _pr_completion_port;
 static PRThread             *_pr_io_completion_thread;
 
 #define RECYCLE_SIZE 512
 static struct _MDLock        _pr_recycle_lock;
 static PRInt32               _pr_recycle_array[RECYCLE_SIZE];
 static PRInt32               _pr_recycle_tail = 0; 
@@ -2296,46 +2297,50 @@ PRInt32
     return (PRInt32)file;
 }
 
 PRInt32 
 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
 {
     PRInt32 f = fd->secret->md.osfd;
     PRUint32 bytes;
-    int rv, err;
+    int rv, err, rc;
+    LONG hiOffset = 0;
 
     if (_nt_use_async && !fd->secret->md.sync_file_io) {
         PRThread *me = _PR_MD_CURRENT_THREAD();
 
         if (me->io_suspended) {
             PR_SetError(PR_INVALID_STATE_ERROR, 0);
             return -1;
         }
 
         memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
 
-        me->md.overlapped.overlapped.Offset = SetFilePointer((HANDLE)f, 0, 0, FILE_CURRENT);
+        me->md.overlapped.overlapped.Offset = SetFilePointer((HANDLE)f, 0, &me->md.overlapped.overlapped.OffsetHigh, FILE_CURRENT);
+        PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() != NO_ERROR));
 
         if (fd->secret->inheritable) {
             rv = ReadFile((HANDLE)f, 
                           (LPVOID)buf, 
                           len, 
                           &bytes, 
                           &me->md.overlapped.overlapped);
             if (rv != 0) {
-                SetFilePointer((HANDLE)f, bytes, 0, FILE_CURRENT);
+                rc = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
+                PR_ASSERT((rc != 0xffffffff) || (GetLastError() != NO_ERROR));
                 return bytes;
             }
             err = GetLastError();
             if (err == ERROR_IO_PENDING) {
                 rv = GetOverlappedResult((HANDLE)f,
                         &me->md.overlapped.overlapped, &bytes, TRUE);
                 if (rv != 0) {
-                    SetFilePointer((HANDLE)f, bytes, 0, FILE_CURRENT);
+                    rc = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
+                    PR_ASSERT((rc != 0xffffffff) || (GetLastError() != NO_ERROR));
                     return bytes;
                 }
                 err = GetLastError();
             }
             if (err == ERROR_HANDLE_EOF) {
                 return 0;
             } else {
                 _PR_MD_MAP_READ_ERROR(err);
@@ -2442,46 +2447,50 @@ PRInt32
     }
 }
 
 PRInt32
 _PR_MD_WRITE(PRFileDesc *fd, void *buf, PRInt32 len)
 {
     PRInt32 f = fd->secret->md.osfd;
     PRInt32 bytes;
-    int rv, err;
+    int rv, err, rc;
+    LONG hiOffset = 0;
 
     if (_nt_use_async && !fd->secret->md.sync_file_io) {
         PRThread *me = _PR_MD_CURRENT_THREAD();
 
         if (me->io_suspended) {
             PR_SetError(PR_INVALID_STATE_ERROR, 0);
             return -1;
         }
 
         memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
 
-        me->md.overlapped.overlapped.Offset = SetFilePointer((HANDLE)f, 0, 0, FILE_CURRENT);
+        me->md.overlapped.overlapped.Offset = SetFilePointer((HANDLE)f, 0, &me->md.overlapped.overlapped.OffsetHigh, FILE_CURRENT);
+        PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() != NO_ERROR));
 
         if (fd->secret->inheritable) {
             rv = WriteFile((HANDLE)f, 
                           (LPVOID)buf, 
                           len, 
                           &bytes, 
                           &me->md.overlapped.overlapped);
             if (rv != 0) {
-                SetFilePointer((HANDLE)f, bytes, 0, FILE_CURRENT);
+                rc = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
+                PR_ASSERT((rc != 0xffffffff) || (GetLastError() != NO_ERROR));
                 return bytes;
             }
             err = GetLastError();
             if (err == ERROR_IO_PENDING) {
                 rv = GetOverlappedResult((HANDLE)f,
                         &me->md.overlapped.overlapped, &bytes, TRUE);
                 if (rv != 0) {
-                    SetFilePointer((HANDLE)f, bytes, 0, FILE_CURRENT);
+                    rc = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
+                    PR_ASSERT((rc != 0xffffffff) || (GetLastError() != NO_ERROR));
                     return bytes;
                 }
                 err = GetLastError();
             }
             _PR_MD_MAP_READ_ERROR(err);
             return -1;
         } else {
             if (!fd->secret->md.io_model_committed) {
@@ -2776,22 +2785,22 @@ PRStatus
 
 /* --- DIR IO ------------------------------------------------------------ */
 #define GetFileFromDIR(d)       (d)->d_entry.cFileName
 #define FileIsHidden(d)       ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
 
 void FlipSlashes(char *cp, int len)
 {
     while (--len >= 0) {
-    if (cp[0] == '/') {
-        cp[0] = PR_DIRECTORY_SEPARATOR;
+        if (cp[0] == '/') {
+            cp[0] = PR_DIRECTORY_SEPARATOR;
+        }
+        cp = _mbsinc(cp);
     }
-    cp++;
-    }
-}
+} /* end FlipSlashes() */
 
 /*
 **
 ** Local implementations of standard Unix RTL functions which are not provided
 ** by the VC RTL.
 **
 */
 
@@ -3080,17 +3089,17 @@ PRInt32
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return -1;
     }
 
     /*
      * FindFirstFile() expands wildcard characters.  So
      * we make sure the pathname contains no wildcard.
      */
-    if (NULL != strpbrk(fn, "?*")) {
+    if (NULL != _mbspbrk(fn, "?*")) {
         PR_SetError(PR_FILE_NOT_FOUND_ERROR, 0);
         return -1;
     }
 
     hFindFile = FindFirstFile(fn, &findFileData);
     if (INVALID_HANDLE_VALUE == hFindFile) {
         DWORD len;
         char *filePart;
@@ -3102,17 +3111,17 @@ PRInt32
          * root directory.  If not, and if the pathname ends in a slash,
          * we remove the final slash and try again.
          */
 
         /*
          * If the pathname does not contain ., \, and /, it cannot be
          * a root directory or a pathname that ends in a slash.
          */
-        if (NULL == strpbrk(fn, ".\\/")) {
+        if (NULL == _mbspbrk(fn, ".\\/")) {
             _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
             return -1;
         } 
         len = GetFullPathName(fn, sizeof(pathbuf), pathbuf,
                 &filePart);
         PR_ASSERT(0 != len);
         if (len > sizeof(pathbuf)) {
             PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);