summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>1999-04-26 22:09:00 +0000
committerwtc%netscape.com <devnull@localhost>1999-04-26 22:09:00 +0000
commit4aedebcee68f21743d7a448b0a35906721bdd48f (patch)
tree09e5e3960e3999fc30d85fffa546d4deb8ebd756
parent9aea53f6b1d7450411fd12f45e217cc38c36270e (diff)
downloadnspr-hg-4aedebcee68f21743d7a448b0a35906721bdd48f.tar.gz
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.
-rw-r--r--pr/src/md/windows/w95io.c74
1 files changed, 50 insertions, 24 deletions
diff --git a/pr/src/md/windows/w95io.c b/pr/src/md/windows/w95io.c
index 12cc9830..7978251e 100644
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -224,41 +224,67 @@ _PR_MD_WRITE(PRFileDesc *fd, void *buf, PRInt32 len)
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;
}
/*