fstat.c revision 38451
138451Smsmith/*	$NetBSD: fstat.c,v 1.1 1996/01/13 22:25:38 leo Exp $	*/
238451Smsmith
338451Smsmith/*-
438451Smsmith * Copyright (c) 1993
538451Smsmith *	The Regents of the University of California.  All rights reserved.
638451Smsmith *
738451Smsmith * Redistribution and use in source and binary forms, with or without
838451Smsmith * modification, are permitted provided that the following conditions
938451Smsmith * are met:
1038451Smsmith * 1. Redistributions of source code must retain the above copyright
1138451Smsmith *    notice, this list of conditions and the following disclaimer.
1238451Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1338451Smsmith *    notice, this list of conditions and the following disclaimer in the
1438451Smsmith *    documentation and/or other materials provided with the distribution.
1538451Smsmith * 3. All advertising materials mentioning features or use of this software
1638451Smsmith *    must display the following acknowledgement:
1738451Smsmith *	This product includes software developed by the University of
1838451Smsmith *	California, Berkeley and its contributors.
1938451Smsmith * 4. Neither the name of the University nor the names of its contributors
2038451Smsmith *    may be used to endorse or promote products derived from this software
2138451Smsmith *    without specific prior written permission.
2238451Smsmith *
2338451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2438451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2538451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2638451Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2738451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2838451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2938451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3038451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3138451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3238451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3338451Smsmith * SUCH DAMAGE.
3438451Smsmith *
3538451Smsmith *	@(#)stat.c	8.1 (Berkeley) 6/11/93
3638451Smsmith */
3738451Smsmith
3838451Smsmith#include "stand.h"
3938451Smsmith
4038451Smsmithint
4138451Smsmithfstat(fd, sb)
4238451Smsmith	int fd;
4338451Smsmith	struct stat *sb;
4438451Smsmith{
4538451Smsmith	register struct open_file *f = &files[fd];
4638451Smsmith
4738451Smsmith	if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
4838451Smsmith		errno = EBADF;
4938451Smsmith		return (-1);
5038451Smsmith	}
5138451Smsmith
5238451Smsmith	/* operation not defined on raw devices */
5338451Smsmith	if (f->f_flags & F_RAW) {
5438451Smsmith		errno = EOPNOTSUPP;
5538451Smsmith		return (-1);
5638451Smsmith	}
5738451Smsmith
5838451Smsmith	errno = (f->f_ops->fo_stat)(f, sb);
5938451Smsmith	return (0);
6038451Smsmith}
61