date and time created 80/12/21 16:50:28 by wnj
[unix-history] / usr / src / lib / libc / stdio / fdopen.c
CommitLineData
39195eb1
BJ
1/* @(#)fdopen.c 4.1 (Berkeley) %G% */
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
11FILE *
12fdopen(fd, mode)
13register char *mode;
14{
15 extern int errno;
16 register FILE *iop;
17 extern FILE *_lastbuf;
18
19 for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
20 if (iop >= _lastbuf)
21 return(NULL);
22 iop->_cnt = 0;
23 iop->_file = fd;
24 if (*mode != 'r') {
25 iop->_flag |= _IOWRT;
26 if (*mode == 'a')
27 lseek(fd, 0L, 2);
28 } else
29 iop->_flag |= _IOREAD;
30 return(iop);
31}