mariadb/storage/bdb/os_win32/os_seek.c

93 lines
1.7 KiB
C
Raw Normal View History

2001-03-04 19:42:05 -05:00
/*-
* See the file LICENSE for redistribution information.
*
2005-12-05 10:27:46 -08:00
* Copyright (c) 1997-2005
2001-03-04 19:42:05 -05:00
* Sleepycat Software. All rights reserved.
2005-07-20 15:48:22 -07:00
*
2005-12-05 10:27:46 -08:00
* $Id: os_seek.c,v 12.1 2005/06/16 20:23:30 bostic Exp $
2001-03-04 19:42:05 -05:00
*/
#include "db_config.h"
#include "db_int.h"
/*
* __os_seek --
* Seek to a page/byte offset in the file.
*/
int
__os_seek(dbenv, fhp, pgsize, pageno, relative, isrewind, db_whence)
DB_ENV *dbenv;
DB_FH *fhp;
2005-07-20 15:48:22 -07:00
u_int32_t pgsize;
2001-03-04 19:42:05 -05:00
db_pgno_t pageno;
u_int32_t relative;
int isrewind;
DB_OS_SEEK db_whence;
{
2002-10-30 15:57:05 +04:00
/* Yes, this really is how Microsoft have designed their API */
union {
__int64 bigint;
struct {
unsigned long low;
long high;
};
2005-07-20 15:48:22 -07:00
} offbytes;
off_t offset;
2001-03-04 19:42:05 -05:00
int ret, whence;
2002-10-30 15:57:05 +04:00
DWORD from;
2001-03-04 19:42:05 -05:00
2005-07-20 15:48:22 -07:00
offset = (off_t)pgsize * pageno + relative;
if (isrewind)
offset = -offset;
2002-10-30 15:57:05 +04:00
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);
}
2001-03-04 19:42:05 -05:00
2005-07-20 15:48:22 -07:00
ret = DB_GLOBAL(j_seek)(fhp->fd, offset, whence);
2002-10-30 15:57:05 +04:00
} 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);
}
2005-07-20 15:48:22 -07:00
offbytes.bigint = offset;
2002-10-30 15:57:05 +04:00
ret = (SetFilePointer(fhp->handle,
2005-07-20 15:48:22 -07:00
offbytes.low, &offbytes.high, from) == (DWORD) - 1) ?
__os_get_errno() : 0;
2001-03-04 19:42:05 -05:00
}
2005-07-20 15:48:22 -07:00
if (ret == 0) {
fhp->pgsize = pgsize;
fhp->pgno = pageno;
fhp->offset = relative;
} else {
2001-03-04 19:42:05 -05:00
__db_err(dbenv, "seek: %lu %d %d: %s",
(u_long)pgsize * pageno + relative,
isrewind, db_whence, strerror(ret));
2005-07-20 15:48:22 -07:00
}
2001-03-04 19:42:05 -05:00
return (ret);
}