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

  1.  
  2. /*
  3.  *  READ.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. read(fd, buf, bytes)
  15. int fd;
  16. 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)) {
  25.         if (d->fd_Exec)
  26.         return((*d->fd_Exec)(d->fd_Fh, IOC_READ, buf, bytes));
  27.         n = Read(d->fd_Fh, buf, bytes);
  28.     } else {
  29.         errno = ENOPERM;
  30.     }
  31.     }
  32.     return(n);
  33. }
  34.  
  35.