From 5ed7f4b11a369c4729ea1debb891c84cea4956f1 Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Mon, 26 Apr 1999 22:09:00 +0000 Subject: [PATCH] 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. --- nsprpub/pr/src/md/windows/w95io.c | 74 +++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/nsprpub/pr/src/md/windows/w95io.c b/nsprpub/pr/src/md/windows/w95io.c index 12cc983005ee..7978251ea5c5 100644 --- a/nsprpub/pr/src/md/windows/w95io.c +++ b/nsprpub/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); + DWORD moveMethod; + LARGE_INTEGER li; + DWORD err; - rv = SetFilePointer((HANDLE)fd->secret->md.osfd, low, &hi, whence); - - /* - * 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; } /*