xref: /original-bsd/sys/stand.att/stat.c (revision 3705696b)
1 /*-
2  * Copyright (c) 1991, 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) 06/11/93
8  */
9 
10 #include <sys/param.h>
11 #include <sys/stat.h>
12 #include <stand.att/saio.h>
13 
14 #ifndef SMALL
15 fstat(fd, sb)
16 	int fd;
17 	struct stat *sb;
18 {
19 	register struct iob *io;
20 
21 	fd -= 3;
22 	if (fd < 0 || fd >= SOPEN_MAX ||
23 	    ((io = &iob[fd])->i_flgs & F_ALLOC) == 0) {
24 		errno = EBADF;
25 		return (-1);
26 	}
27 	/* only important stuff */
28 	sb->st_mode = io->i_ino.di_mode;
29 	sb->st_uid = io->i_ino.di_uid;
30 	sb->st_gid = io->i_ino.di_gid;
31 	sb->st_size = io->i_ino.di_size;
32 	return (0);
33 }
34 
35 stat(str, sb)
36 	const char *str;
37 	struct stat *sb;
38 {
39 	int fd, rv;
40 
41 	fd = open(str, 0);
42 	if (fd < 0)
43 		return(-1);
44 	rv = fstat(fd, sb);
45 	close(fd);
46 	return(rv);
47 }
48 #endif /* SMALL */
49