xref: /original-bsd/sys/stand.att/lseek.c (revision db5a9834)
1*db5a9834Sbostic /*-
2*db5a9834Sbostic  * Copyright (c) 1982, 1988 The Regents of the University of California.
3*db5a9834Sbostic  * All rights reserved.
4*db5a9834Sbostic  *
5*db5a9834Sbostic  * %sccs.include.proprietary.c%
6*db5a9834Sbostic  *
7*db5a9834Sbostic  *	@(#)lseek.c	7.1 (Berkeley) 05/05/91
8*db5a9834Sbostic  */
9*db5a9834Sbostic 
10*db5a9834Sbostic #include <sys/param.h>
11*db5a9834Sbostic #include "saio.h"
12*db5a9834Sbostic 
13*db5a9834Sbostic lseek(fdesc, addr, ptr)
14*db5a9834Sbostic 	int fdesc, ptr;
15*db5a9834Sbostic 	off_t addr;
16*db5a9834Sbostic {
17*db5a9834Sbostic 	register struct iob *io;
18*db5a9834Sbostic 
19*db5a9834Sbostic #ifndef SMALL
20*db5a9834Sbostic 	if (ptr != L_SET) {
21*db5a9834Sbostic 		printf("Seek not from beginning of file\n");
22*db5a9834Sbostic 		errno = EOFFSET;
23*db5a9834Sbostic 		return (-1);
24*db5a9834Sbostic 	}
25*db5a9834Sbostic #endif
26*db5a9834Sbostic 	fdesc -= 3;
27*db5a9834Sbostic #ifndef SMALL
28*db5a9834Sbostic 	if (fdesc < 0 || fdesc >= SOPEN_MAX ||
29*db5a9834Sbostic 	    ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) {
30*db5a9834Sbostic 		errno = EBADF;
31*db5a9834Sbostic 		return (-1);
32*db5a9834Sbostic 	}
33*db5a9834Sbostic #endif
34*db5a9834Sbostic 	io->i_offset = addr;
35*db5a9834Sbostic 	io->i_bn = addr / DEV_BSIZE;
36*db5a9834Sbostic 	io->i_cc = 0;
37*db5a9834Sbostic 	return (0);
38*db5a9834Sbostic }
39