| 1 | /*- |
| 2 | * Copyright (c) 1993 |
| 3 | * The Regents of the University of California. All rights reserved. |
| 4 | * |
| 5 | * %sccs.include.redist.c% |
| 6 | * |
| 7 | * @(#)stat.c 8.1 (Berkeley) %G% |
| 8 | */ |
| 9 | |
| 10 | #include <stand/stand.h> |
| 11 | |
| 12 | fstat(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 | |
| 33 | stat(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 | } |