1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997, 1998, 1999
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char sccsid[] = "@(#)os_seek.c 11.3 (Sleepycat) 10/29/99";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#ifdef _MSC_VER /* _WIN32 */
#include <io.h>
#else
#include <unistd.h>
#endif
#endif
#include "db_int.h"
#include "os_jump.h"
/*
* CDB___os_seek --
* Seek to a page/byte offset in the file.
*
* PUBLIC: int CDB___os_seek
* PUBLIC: __P((DB_FH *, size_t, db_pgno_t, u_int32_t, int, DB_OS_SEEK));
*/
int
CDB___os_seek(fhp, pgsize, pageno, relative, isrewind, db_whence)
DB_FH *fhp;
size_t pgsize;
db_pgno_t pageno;
u_int32_t relative;
int isrewind;
DB_OS_SEEK db_whence;
{
off_t offset;
int whence;
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 (CDB___db_jump.j_seek != NULL)
return (CDB___db_jump.j_seek(fhp->fd, pgsize, pageno,
relative, isrewind, whence) == -1 ? CDB___os_get_errno() : 0);
offset = (off_t)pgsize * pageno + relative;
if (isrewind)
offset = -offset;
return (lseek(fhp->fd, offset, whence) == -1 ? CDB___os_get_errno() : 0);
}
|