3 * _fstat.c - fstat() for Network Support Library (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
10 #include <sys/types.h>
11 #include <sys/socket.h>
18 /* DOS 3.0 and MuFS extensions to file info block */
20 #include <proto/dos.h>
21 #include <proto/utility.h>
25 int fstat(int fd
, struct stat
*st
)
27 struct UFB
*ufb
= chkufb(fd
);
29 if (st
== NULL
|| ((1 & (long)st
) == 1)) {
34 if (ufb
== NULL
|| ufb
->ufbflg
== 0) {
39 if (ufb
->ufbflg
& UFB_SOCK
) { /* a socket */
41 long size
= sizeof(value
);
42 bzero(st
, sizeof(*st
));
44 /* st->st_dev = ??? */
45 st
->st_mode
= S_IFSOCK
| S_IRUSR
| S_IWUSR
;
46 st
->st_uid
= geteuid();
47 st
->st_gid
= getegid();
49 if (getsockopt(fd
, SOL_SOCKET
, SO_SNDBUF
, &value
, &size
) == 0)
50 st
->st_blksize
= value
;
53 } else { /* ordinal file */
54 /* test if it is a NIL: file handle (ExamineFH() crashes on those!) */
55 if (((struct FileHandle
*)BADDR((BPTR
)ufb
->ufbfh
))->fh_Type
== NULL
) {
56 /* It is NIL:, make up something... */
57 bzero(st
, sizeof(*st
));
58 st
->st_mode
= S_IFIFO
| S_IRWXU
| S_IRWXG
| S_IRWXO
;
62 if (ExamineFH(ufb
->ufbfh
, __dostat_fib
)) {
63 __dostat(__dostat_fib
, st
);
64 st
->st_dev
= (dev_t
)((struct FileHandle
*)BADDR(ufb
->ufbfh
))->fh_Type
;