xref: /openbsd/sys/lib/libsa/lseek.c (revision df930be7)
1*df930be7Sderaadt /*	$NetBSD: lseek.c,v 1.2 1994/10/26 05:44:51 cgd Exp $	*/
2*df930be7Sderaadt 
3*df930be7Sderaadt /*-
4*df930be7Sderaadt  * Copyright (c) 1993
5*df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
6*df930be7Sderaadt  *
7*df930be7Sderaadt  * This code is derived from software contributed to Berkeley by
8*df930be7Sderaadt  * The Mach Operating System project at Carnegie-Mellon University.
9*df930be7Sderaadt  *
10*df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
11*df930be7Sderaadt  * modification, are permitted provided that the following conditions
12*df930be7Sderaadt  * are met:
13*df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
14*df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
15*df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
16*df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
17*df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
18*df930be7Sderaadt  * 3. All advertising materials mentioning features or use of this software
19*df930be7Sderaadt  *    must display the following acknowledgement:
20*df930be7Sderaadt  *	This product includes software developed by the University of
21*df930be7Sderaadt  *	California, Berkeley and its contributors.
22*df930be7Sderaadt  * 4. Neither the name of the University nor the names of its contributors
23*df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
24*df930be7Sderaadt  *    without specific prior written permission.
25*df930be7Sderaadt  *
26*df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27*df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28*df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29*df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30*df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31*df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32*df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33*df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34*df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35*df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36*df930be7Sderaadt  * SUCH DAMAGE.
37*df930be7Sderaadt  *
38*df930be7Sderaadt  *	@(#)lseek.c	8.1 (Berkeley) 6/11/93
39*df930be7Sderaadt  *
40*df930be7Sderaadt  *
41*df930be7Sderaadt  * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University
42*df930be7Sderaadt  * All Rights Reserved.
43*df930be7Sderaadt  *
44*df930be7Sderaadt  * Author: Alessandro Forin
45*df930be7Sderaadt  *
46*df930be7Sderaadt  * Permission to use, copy, modify and distribute this software and its
47*df930be7Sderaadt  * documentation is hereby granted, provided that both the copyright
48*df930be7Sderaadt  * notice and this permission notice appear in all copies of the
49*df930be7Sderaadt  * software, derivative works or modified versions, and any portions
50*df930be7Sderaadt  * thereof, and that both notices appear in supporting documentation.
51*df930be7Sderaadt  *
52*df930be7Sderaadt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53*df930be7Sderaadt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
54*df930be7Sderaadt  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55*df930be7Sderaadt  *
56*df930be7Sderaadt  * Carnegie Mellon requests users of this software to return to
57*df930be7Sderaadt  *
58*df930be7Sderaadt  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
59*df930be7Sderaadt  *  School of Computer Science
60*df930be7Sderaadt  *  Carnegie Mellon University
61*df930be7Sderaadt  *  Pittsburgh PA 15213-3890
62*df930be7Sderaadt  *
63*df930be7Sderaadt  * any improvements or extensions that they make and grant Carnegie the
64*df930be7Sderaadt  * rights to redistribute these changes.
65*df930be7Sderaadt  */
66*df930be7Sderaadt 
67*df930be7Sderaadt #include "stand.h"
68*df930be7Sderaadt 
69*df930be7Sderaadt off_t
70*df930be7Sderaadt lseek(fd, offset, where)
71*df930be7Sderaadt 	int fd;
72*df930be7Sderaadt 	off_t offset;
73*df930be7Sderaadt 	int where;
74*df930be7Sderaadt {
75*df930be7Sderaadt 	register struct open_file *f = &files[fd];
76*df930be7Sderaadt 
77*df930be7Sderaadt 	if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
78*df930be7Sderaadt 		errno = EBADF;
79*df930be7Sderaadt 		return (-1);
80*df930be7Sderaadt 	}
81*df930be7Sderaadt 
82*df930be7Sderaadt 	/* seek is not supported on raw devices */
83*df930be7Sderaadt 	if (f->f_flags & F_RAW) {
84*df930be7Sderaadt 		errno = EOFFSET;
85*df930be7Sderaadt 		return ((off_t)-1);
86*df930be7Sderaadt 	}
87*df930be7Sderaadt 
88*df930be7Sderaadt 	return (f->f_ops->seek)(f, offset, where);
89*df930be7Sderaadt }
90