Commit | Line | Data |
---|---|---|
18e5fa7e BJ |
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 | extern int errno; | |
15 | register FILE *iop; | |
16 | extern FILE *_lastbuf; | |
17 | ||
18 | for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++) | |
19 | if (iop >= _lastbuf) | |
20 | return(NULL); | |
21 | iop->_cnt = 0; | |
22 | iop->_file = fd; | |
23 | if (*mode != 'r') { | |
24 | iop->_flag |= _IOWRT; | |
25 | if (*mode == 'a') | |
26 | lseek(fd, 0L, 2); | |
27 | } else | |
28 | iop->_flag |= _IOREAD; | |
29 | return(iop); | |
30 | } |