1*7c478bd9Sstevel@tonic-gate /*-
2*7c478bd9Sstevel@tonic-gate * See the file LICENSE for redistribution information.
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1997, 1998
5*7c478bd9Sstevel@tonic-gate * Sleepycat Software. All rights reserved.
6*7c478bd9Sstevel@tonic-gate */
7*7c478bd9Sstevel@tonic-gate
8*7c478bd9Sstevel@tonic-gate #include "config.h"
9*7c478bd9Sstevel@tonic-gate
10*7c478bd9Sstevel@tonic-gate #ifndef lint
11*7c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)os_seek.c 10.11 (Sleepycat) 10/12/98";
12*7c478bd9Sstevel@tonic-gate #endif /* not lint */
13*7c478bd9Sstevel@tonic-gate
14*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES
15*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
16*7c478bd9Sstevel@tonic-gate
17*7c478bd9Sstevel@tonic-gate #include <errno.h>
18*7c478bd9Sstevel@tonic-gate #include <unistd.h>
19*7c478bd9Sstevel@tonic-gate #endif
20*7c478bd9Sstevel@tonic-gate
21*7c478bd9Sstevel@tonic-gate #include "db_int.h"
22*7c478bd9Sstevel@tonic-gate #include "os_jump.h"
23*7c478bd9Sstevel@tonic-gate
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate * __os_seek --
26*7c478bd9Sstevel@tonic-gate * Seek to a page/byte offset in the file.
27*7c478bd9Sstevel@tonic-gate *
28*7c478bd9Sstevel@tonic-gate * PUBLIC: int __os_seek __P((int, size_t, db_pgno_t, u_int32_t, int, int));
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate int
__os_seek(fd,pgsize,pageno,relative,isrewind,whence)31*7c478bd9Sstevel@tonic-gate __os_seek(fd, pgsize, pageno, relative, isrewind, whence)
32*7c478bd9Sstevel@tonic-gate int fd;
33*7c478bd9Sstevel@tonic-gate size_t pgsize;
34*7c478bd9Sstevel@tonic-gate db_pgno_t pageno;
35*7c478bd9Sstevel@tonic-gate u_int32_t relative;
36*7c478bd9Sstevel@tonic-gate int isrewind, whence;
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate off_t offset;
39*7c478bd9Sstevel@tonic-gate int ret;
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate if (__db_jump.j_seek != NULL)
42*7c478bd9Sstevel@tonic-gate ret = __db_jump.j_seek(fd,
43*7c478bd9Sstevel@tonic-gate pgsize, pageno, relative, isrewind, whence);
44*7c478bd9Sstevel@tonic-gate else {
45*7c478bd9Sstevel@tonic-gate offset = (off_t)pgsize * pageno + relative;
46*7c478bd9Sstevel@tonic-gate if (isrewind)
47*7c478bd9Sstevel@tonic-gate offset = -offset;
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate ret = lseek(fd, offset, whence);
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate return (ret == -1 ? errno : 0);
52*7c478bd9Sstevel@tonic-gate }
53