1*1999Swnj /* @(#)fdopen.c 4.1 (Berkeley) 12/21/80 */ 2*1999Swnj /* 3*1999Swnj * Unix routine to do an "fopen" on file descriptor 4*1999Swnj * The mode has to be repeated because you can't query its 5*1999Swnj * status 6*1999Swnj */ 7*1999Swnj 8*1999Swnj #include <stdio.h> 9*1999Swnj #include <errno.h> 10*1999Swnj 11*1999Swnj FILE * 12*1999Swnj fdopen(fd, mode) 13*1999Swnj register char *mode; 14*1999Swnj { 15*1999Swnj extern int errno; 16*1999Swnj register FILE *iop; 17*1999Swnj extern FILE *_lastbuf; 18*1999Swnj 19*1999Swnj for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++) 20*1999Swnj if (iop >= _lastbuf) 21*1999Swnj return(NULL); 22*1999Swnj iop->_cnt = 0; 23*1999Swnj iop->_file = fd; 24*1999Swnj if (*mode != 'r') { 25*1999Swnj iop->_flag |= _IOWRT; 26*1999Swnj if (*mode == 'a') 27*1999Swnj lseek(fd, 0L, 2); 28*1999Swnj } else 29*1999Swnj iop->_flag |= _IOREAD; 30*1999Swnj return(iop); 31*1999Swnj } 32