Commit | Line | Data |
---|---|---|
2c344bd0 TL |
1 | #include <stdio.h> |
2 | #include <errno.h> | |
3 | ||
4 | FILE * | |
5 | fopen(file, mode) | |
6 | char *file; | |
7 | register char *mode; | |
8 | { | |
9 | extern int errno; | |
10 | register f; | |
11 | register FILE *iop; | |
12 | extern FILE *_lastbuf; | |
13 | ||
14 | for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++) | |
15 | if (iop >= _lastbuf) | |
16 | return(NULL); | |
17 | if (*mode=='w') | |
18 | f = creat(file, 0666); | |
19 | else if (*mode=='a') { | |
20 | if ((f = open(file, 1)) < 0) { | |
21 | if (errno == ENOENT) | |
22 | f = creat(file, 0666); | |
23 | } | |
24 | lseek(f, 0L, 2); | |
25 | } else | |
26 | f = open(file, 0); | |
27 | if (f < 0) | |
28 | return(NULL); | |
29 | iop->_cnt = 0; | |
30 | iop->_file = f; | |
31 | if (*mode != 'r') | |
32 | iop->_flag |= _IOWRT; | |
33 | else | |
34 | iop->_flag |= _IOREAD; | |
35 | return(iop); | |
36 | } |