home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / internet-tools / amitcp / amitcp-sdk-4.3 / src / netlib / _fstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-17  |  1.7 KB  |  76 lines

  1. RCS_ID_C="$Id: _fstat.c,v 4.2 1995/09/17 20:52:30 jraja Exp $";
  2. /*
  3.  *      _fstat.c - fstat() for Network Support Library (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <sys/socket.h>
  12. #include <sys/stat.h>
  13. #include <errno.h>
  14.  
  15. #include <string.h>
  16. #include <stdlib.h>
  17.  
  18. /* DOS 3.0 and MuFS extensions to file info block */
  19. #include "fibex.h"
  20. #include <proto/dos.h>
  21. #include <proto/utility.h>
  22.  
  23. #include <ios1.h>
  24.  
  25. int fstat(int fd, struct stat *st)
  26. {
  27.   struct UFB *ufb = chkufb(fd);
  28.  
  29.   if (st == NULL || ((1 & (long)st) == 1)) {
  30.     errno = EFAULT;
  31.     return -1;
  32.   }
  33.  
  34.   if (ufb == NULL || ufb->ufbflg == 0) {
  35.     errno = EBADF;
  36.     return -1;
  37.   }
  38.  
  39.   if (ufb->ufbflg & UFB_SOCK) { /* a socket */
  40.     long value;
  41.     long size = sizeof(value);
  42.     bzero(st, sizeof(*st));
  43.  
  44.     /* st->st_dev = ??? */
  45.     st->st_mode = S_IFSOCK | S_IRUSR | S_IWUSR;
  46.     st->st_uid = geteuid();
  47.     st->st_gid = getegid();
  48.  
  49.     if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &size) == 0)
  50.       st->st_blksize = value;
  51.  
  52.     return 0;
  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;
  59.       return 0;
  60.     }
  61.     else {
  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;
  65.     return 0;
  66.       } else {
  67.     errno = EIO;
  68.     return -1;
  69.       }
  70.     }
  71.   }
  72. }
  73.  
  74.  
  75.  
  76.