Annotation of 40BSD/libc/stdio/fopen.c, revision 1.1.1.1

1.1       root        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:                if (f >= 0)
                     25:                        lseek(f, 0L, 2);
                     26:        } else
                     27:                f = open(file, 0);
                     28:        if (f < 0)
                     29:                return(NULL);
                     30:        iop->_cnt = 0;
                     31:        iop->_file = f;
                     32:        if (*mode != 'r')
                     33:                iop->_flag |= _IOWRT;
                     34:        else
                     35:                iop->_flag |= _IOREAD;
                     36:        return(iop);
                     37: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.