Annotation of researchv9/libc/stdio/freopen.c, revision 1.1

1.1     ! root        1: /* @(#)freopen.c       4.2 (Berkeley) 3/9/81 */
        !             2: #include       <stdio.h>
        !             3: #include       <errno.h>
        !             4: 
        !             5: FILE *
        !             6: freopen(file, mode, iop)
        !             7: char *file;
        !             8: register char *mode;
        !             9: register FILE *iop;
        !            10: {
        !            11:        extern int errno;
        !            12:        register f, rw;
        !            13: 
        !            14:        rw = mode[1] == '+';
        !            15: 
        !            16:        if (*mode=='w') {
        !            17:                f = creat(file, 0666);
        !            18:                if (rw && f>=0) {
        !            19:                        close(f);
        !            20:                        f = open(file, 2);
        !            21:                }
        !            22:        } else if (*mode=='a') {
        !            23:                if ((f = open(file, rw? 2: 1)) < 0) {
        !            24:                        if (errno == ENOENT) {
        !            25:                                f = creat(file, 0666);
        !            26:                                if (rw && f>=0) {
        !            27:                                        close(f);
        !            28:                                        f = open(file, 2);
        !            29:                                }
        !            30:                        }
        !            31:                }
        !            32:                if (f >= 0)
        !            33:                        lseek(f, 0L, 2);
        !            34:        } else
        !            35:                f = open(file, rw? 2: 0);
        !            36:        fclose(iop);
        !            37:        if (f < 0)
        !            38:                return(NULL);
        !            39:        iop->_cnt = 0;
        !            40:        iop->_file = f;
        !            41:        if (rw)
        !            42:                iop->_flag |= _IORW;
        !            43:        else if (*mode != 'r')
        !            44:                iop->_flag |= _IOWRT;
        !            45:        else
        !            46:                iop->_flag |= _IOREAD;
        !            47:        return(iop);
        !            48: }

unix.superglobalmegacorp.com

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