date and time created 80/12/21 16:50:24 by wnj
[unix-history] / usr / src / lib / libc / stdio / freopen.c
CommitLineData
2de31004
BJ
1/* @(#)freopen.c 4.1 (Berkeley) %G% */
2#include <stdio.h>
3
4FILE *
5freopen(file, mode, iop)
6char *file;
7register char *mode;
8register FILE *iop;
9{
10 register f;
11
12 fclose(iop);
13 if (*mode=='w')
14 f = creat(file, 0666);
15 else if (*mode=='a') {
16 if ((f = open(file, 1)) < 0)
17 f = creat(file, 0666);
18 lseek(f, 0L, 2);
19 } else
20 f = open(file, 0);
21 if (f < 0)
22 return(NULL);
23 iop->_file = f;
24 if (*mode != 'r')
25 iop->_flag |= _IOWRT;
26 else
27 iop->_flag |= _IOREAD;
28 return(iop);
29}