Commit | Line | Data |
---|---|---|
1 | /* @(#)freopen.c 4.1 (Berkeley) %G% */ | |
2 | #include <stdio.h> | |
3 | ||
4 | FILE * | |
5 | freopen(file, mode, iop) | |
6 | char *file; | |
7 | register char *mode; | |
8 | register 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 | } |