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