home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / fd / write.c < prev   
Encoding:
C/C++ Source or Header  |  1990-05-30  |  601 b   |  38 lines

  1.  
  2. /*
  3.  *  WRITE.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. unsigned int
  14. write(fd, buf, bytes)
  15. int fd;
  16. const void *buf;
  17. unsigned int bytes;
  18. {
  19.     _IOFDS *d;
  20.     int n = -1;
  21.  
  22.     chkabort();
  23.     if (d = __getfh(fd)) {
  24.     if (d->fd_Flags & (O_WRONLY|O_RDWR|O_APPEND)) {
  25.         if (d->fd_Exec)
  26.         return((*d->fd_Exec)(d->fd_Fh, IOC_WRITE, buf, bytes));
  27.  
  28.         if (d->fd_Flags & O_APPEND)
  29.         Seek(d->fd_Fh, 0L, 1);
  30.         n = Write(d->fd_Fh, buf, bytes);
  31.     } else {
  32.         errno = ENOPERM;
  33.     }
  34.     }
  35.     return(n);
  36. }
  37.  
  38.