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