diff options
Diffstat (limited to 'bdb/os_win32/os_seek.c')
-rw-r--r-- | bdb/os_win32/os_seek.c | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/bdb/os_win32/os_seek.c b/bdb/os_win32/os_seek.c index 8cf3c98aa91..40140f51534 100644 --- a/bdb/os_win32/os_seek.c +++ b/bdb/os_win32/os_seek.c @@ -1,18 +1,17 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1997, 1998, 1999, 2000 + * Copyright (c) 1997-2002 * Sleepycat Software. All rights reserved. */ #include "db_config.h" #ifndef lint -static const char revid[] = "$Id: os_seek.c,v 11.8 2000/05/17 19:30:19 bostic Exp $"; +static const char revid[] = "$Id: os_seek.c,v 11.17 2002/08/06 04:56:20 bostic Exp $"; #endif /* not lint */ #include "db_int.h" -#include "os_jump.h" /* * __os_seek -- @@ -28,32 +27,56 @@ __os_seek(dbenv, fhp, pgsize, pageno, relative, isrewind, db_whence) int isrewind; DB_OS_SEEK db_whence; { - __int64 offset; + /* Yes, this really is how Microsoft have designed their API */ + union { + __int64 bigint; + struct { + unsigned long low; + long high; + }; + } offset; int ret, whence; + DWORD from; - switch (db_whence) { - case DB_OS_SEEK_CUR: - whence = SEEK_CUR; - break; - case DB_OS_SEEK_END: - whence = SEEK_END; - break; - case DB_OS_SEEK_SET: - whence = SEEK_SET; - break; - default: - return (EINVAL); - } + if (DB_GLOBAL(j_seek) != NULL) { + switch (db_whence) { + case DB_OS_SEEK_CUR: + whence = SEEK_CUR; + break; + case DB_OS_SEEK_END: + whence = SEEK_END; + break; + case DB_OS_SEEK_SET: + whence = SEEK_SET; + break; + default: + return (EINVAL); + } - if (__db_jump.j_seek != NULL) - ret = __db_jump.j_seek(fhp->fd, pgsize, pageno, + ret = DB_GLOBAL(j_seek)(fhp->fd, pgsize, pageno, relative, isrewind, whence); - else { - offset = (__int64)pgsize * pageno + relative; + } else { + switch (db_whence) { + case DB_OS_SEEK_CUR: + from = FILE_CURRENT; + break; + case DB_OS_SEEK_END: + from = FILE_END; + break; + case DB_OS_SEEK_SET: + from = FILE_BEGIN; + break; + default: + return (EINVAL); + } + + offset.bigint = (__int64)pgsize * pageno + relative; if (isrewind) - offset = -offset; - ret = _lseeki64( - fhp->fd, offset, whence) == -1 ? __os_get_errno() : 0; + offset.bigint = -offset.bigint; + + ret = (SetFilePointer(fhp->handle, + offset.low, &offset.high, from) == (DWORD) - 1) ? + __os_win32_errno() : 0; } if (ret != 0) |