home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / libc / stdio / fdopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-05-05  |  630 b   |  46 lines

  1. /*
  2.  * Unix routine to do an "fopen" on file descriptor
  3.  * The mode has to be repeated because you can't query its
  4.  * status
  5.  */
  6.  
  7. #include    <stdio.h>
  8. #include    <errno.h>
  9.  
  10. FILE *
  11. fdopen(fd, mode)
  12.     register char *mode;
  13. {
  14.     register FILE *iop;
  15.     FILE *_findiop();
  16.  
  17.     if ((iop = _findiop()) == NULL)
  18.         return(NULL);
  19.  
  20.     iop->_cnt = 0;
  21.     iop->_file = fd;
  22.     switch (*mode) {
  23.  
  24.     case 'r':
  25.         iop->_flag |= _IOREAD;
  26.         break;
  27.  
  28.     case 'a':
  29.         lseek(fd, 0L, 2);
  30.         /* No break */
  31.     case 'w':
  32.         iop->_flag |= _IOWRT;
  33.         break;
  34.  
  35.     default:
  36.         return(NULL);
  37.     }
  38.  
  39.     if (mode[1] == '+') {
  40.         iop->_flag &= ~(_IOREAD|_IOWRT);
  41.         iop->_flag |= _IORW;
  42.     }
  43.  
  44.     return(iop);
  45. }
  46.