fstat.c revision 38451
1257099Srpaulo/*	$NetBSD: fstat.c,v 1.1 1996/01/13 22:25:38 leo Exp $	*/
2257099Srpaulo
3264483Sjmmv/*-
4264483Sjmmv * Copyright (c) 1993
5257099Srpaulo *	The Regents of the University of California.  All rights reserved.
6257099Srpaulo *
7257099Srpaulo * Redistribution and use in source and binary forms, with or without
8257099Srpaulo * modification, are permitted provided that the following conditions
9264483Sjmmv * are met:
10264483Sjmmv * 1. Redistributions of source code must retain the above copyright
11264483Sjmmv *    notice, this list of conditions and the following disclaimer.
12257099Srpaulo * 2. Redistributions in binary form must reproduce the above copyright
13257099Srpaulo *    notice, this list of conditions and the following disclaimer in the
14257099Srpaulo *    documentation and/or other materials provided with the distribution.
15257099Srpaulo * 3. All advertising materials mentioning features or use of this software
16257099Srpaulo *    must display the following acknowledgement:
17257099Srpaulo *	This product includes software developed by the University of
18257099Srpaulo *	California, Berkeley and its contributors.
19257099Srpaulo * 4. Neither the name of the University nor the names of its contributors
20257099Srpaulo *    may be used to endorse or promote products derived from this software
21257099Srpaulo *    without specific prior written permission.
22257099Srpaulo *
23257099Srpaulo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24257099Srpaulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25257099Srpaulo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26257099Srpaulo * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27257099Srpaulo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28257099Srpaulo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29257099Srpaulo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30257099Srpaulo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31259962Sjmmv * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32257099Srpaulo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33257099Srpaulo * SUCH DAMAGE.
34257099Srpaulo *
35257099Srpaulo *	@(#)stat.c	8.1 (Berkeley) 6/11/93
36257099Srpaulo */
37257099Srpaulo
38257099Srpaulo#include "stand.h"
39257099Srpaulo
40257099Srpauloint
41257099Srpaulofstat(fd, sb)
42259962Sjmmv	int fd;
43257099Srpaulo	struct stat *sb;
44257099Srpaulo{
45257099Srpaulo	register struct open_file *f = &files[fd];
46257099Srpaulo
47257099Srpaulo	if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
48257099Srpaulo		errno = EBADF;
49257099Srpaulo		return (-1);
50257099Srpaulo	}
51257099Srpaulo
52257099Srpaulo	/* operation not defined on raw devices */
53260037Sjmmv	if (f->f_flags & F_RAW) {
54260037Sjmmv		errno = EOPNOTSUPP;
55260037Sjmmv		return (-1);
56260037Sjmmv	}
57260037Sjmmv
58260037Sjmmv	errno = (f->f_ops->fo_stat)(f, sb);
59260037Sjmmv	return (0);
60276423Sngie}
61276423Sngie