4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / sys / stand / stat.c
CommitLineData
b0a80f2e 1/*-
80409bdc
KB
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
b0a80f2e
KM
4 *
5 * %sccs.include.redist.c%
6 *
80409bdc 7 * @(#)stat.c 8.1 (Berkeley) %G%
b0a80f2e
KM
8 */
9
10#include <stand/stand.h>
11
12fstat(fd, sb)
13 int fd;
14 struct stat *sb;
15{
16 register struct open_file *f = &files[fd];
17
18 if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
19 errno = EBADF;
20 return (-1);
21 }
22
23 /* operation not defined on raw devices */
24 if (f->f_flags & F_RAW) {
25 errno = EOPNOTSUPP;
26 return (-1);
27 }
28
29 errno = (f->f_ops->stat)(f, sb);
30 return (0);
31}
32
33stat(str, sb)
34 const char *str;
35 struct stat *sb;
36{
37 int fd, rv;
38
39 fd = open(str, 0);
40 if (fd < 0)
41 return (-1);
42 rv = fstat(fd, sb);
43 (void)close(fd);
44 return (rv);
45}