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