Bugzilla bug #5518: map PRSeekWhence to FILE_XXX before passing to
authorwtc%netscape.com
Mon, 26 Apr 1999 22:09:00 +0000
changeset 584 8ba3ef7d0b60c92efa15090ec9e47e0ab885bfdc
parent 582 871b822c9a95ba55dda084f7c1052dea99330e00
child 585 564379782dd98cd771005f207db07e30cd185fe3
child 586 e065e52999b392f70ae4cca49c715b252adb88c7
push idunknown
push userunknown
push dateunknown
bugs5518, 5520
Bugzilla bug #5518: map PRSeekWhence to FILE_XXX before passing to SetFilePointer. Bugzilla bug #5520: correctly check for failure status of SetFilePointer when invoked with a non-NULL third argument.
pr/src/md/windows/w95io.c
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -219,51 +219,77 @@ PRInt32
         return -1;
     }
     return bytes;
 } /* --- end _PR_MD_WRITE() --- */
 
 PRInt32
 _PR_MD_LSEEK(PRFileDesc *fd, PRInt32 offset, int whence)
 {
+    DWORD moveMethod;
     PRInt32 rv;
 
-    rv = SetFilePointer((HANDLE)fd->secret->md.osfd, offset, 0, whence);
+    switch (whence) {
+        case PR_SEEK_SET:
+            moveMethod = FILE_BEGIN;
+            break;
+        case PR_SEEK_CUR:
+            moveMethod = FILE_CURRENT;
+            break;
+        case PR_SEEK_END:
+            moveMethod = FILE_END;
+            break;
+        default:
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            return -1;
+    }
 
-	/*
-	 * If the lpDistanceToMoveHigh argument (third argument) is
-	 * NULL, SetFilePointer returns 0xffffffff on failure.
-	 */
-	if (-1 == rv) {
-		_PR_MD_MAP_LSEEK_ERROR(GetLastError());
-		return -1;
-	} else
-		return rv;
+    rv = SetFilePointer((HANDLE)fd->secret->md.osfd, offset, NULL, moveMethod);
+
+    /*
+     * If the lpDistanceToMoveHigh argument (third argument) is
+     * NULL, SetFilePointer returns 0xffffffff on failure.
+     */
+    if (-1 == rv) {
+        _PR_MD_MAP_LSEEK_ERROR(GetLastError());
+    }
+    return rv;
 }
 
 PRInt64
 _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, int whence)
 {
-    PRInt64 result;
-    PRInt32 rv, low = (PRInt32)offset, hi = (PRInt32)(offset >> 32);
-
-    rv = SetFilePointer((HANDLE)fd->secret->md.osfd, low, &hi, whence);
+    DWORD moveMethod;
+    LARGE_INTEGER li;
+    DWORD err;
 
-	/*
-	 * If the lpDistanceToMoveHigh argument (third argument) is
-	 * NULL, SetFilePointer returns 0xffffffff on failure.
-	 */
-	if (-1 == rv)
-    {
-		_PR_MD_MAP_LSEEK_ERROR(GetLastError());
-        return -1;
+    switch (whence) {
+        case PR_SEEK_SET:
+            moveMethod = FILE_BEGIN;
+            break;
+        case PR_SEEK_CUR:
+            moveMethod = FILE_CURRENT;
+            break;
+        case PR_SEEK_END:
+            moveMethod = FILE_END;
+            break;
+        default:
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            return -1;
     }
 
-    result = (hi << 32) + rv;
-	return result;
+    li.QuadPart = offset;
+    li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
+            li.LowPart, &li.HighPart, moveMethod);
+
+    if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
+        _PR_MD_MAP_LSEEK_ERROR(err);
+        li.QuadPart = -1;
+    }
+    return li.QuadPart;
 }
 
 /*
  * This is documented to succeed on read-only files, but Win32's
  * FlushFileBuffers functions fails with "access denied" in such a
  * case.  So we only signal an error if the error is *not* "access
  * denied".
  */