home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / fd / close.c next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  609 b   |  44 lines

  1.  
  2. /*
  3.  *  CLOSE.C
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10. #include <ioctl.h>
  11. #include <errno.h>
  12.  
  13. void
  14. __closeall()
  15. {
  16.     short fd;
  17.  
  18.     for (fd = 0; fd < _IoFDLimit; ++fd)
  19.     close(fd);
  20. }
  21.  
  22. int
  23. close(fd)
  24. int fd;
  25. {
  26.     _IOFDS *d;
  27.     int r = -1;
  28.  
  29.     if (d = __getfh(fd)) {
  30.     if (d->fd_Exec) {                       /*  special */
  31.         r = (*d->fd_Exec)(d->fd_Fh, IOC_CLOSE, NULL);
  32.     } else {
  33.         r = 0;
  34.         if ((d->fd_Flags & O_NOCLOSE) == 0)
  35.         Close(d->fd_Fh);
  36.     }
  37.     d->fd_Flags = 0;
  38.     d->fd_Exec  = NULL;
  39.     d->fd_Fh    = NULL;
  40.     }
  41.     return(r);
  42. }
  43.  
  44.