Annotation of researchv10no/cmd/spitbol/osopen.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     osopen( ioptr ) ensures that the file represented by the ioblk
        !             3:  *     is open.
        !             4:  */
        !             5: 
        !             6: #include "spitblks.h"
        !             7: #include "spitio.h"
        !             8: 
        !             9: int    osopen( ioptr )
        !            10: 
        !            11: struct ioblk   *ioptr;
        !            12: 
        !            13: {
        !            14:        int     fd = -1, len, savchr;
        !            15:        char    *cp;
        !            16:        struct  scblk   *scptr;
        !            17: 
        !            18:        if ( ioptr -> flg & IO_OPN )
        !            19:                return 0;
        !            20: 
        !            21:        scptr   = ioptr -> fnm;
        !            22:        cp      = scptr -> str;
        !            23: 
        !            24:        len     = lenfnm( scptr );
        !            25:        if ( cp[0] == '!' ) {
        !            26:                ioptr -> flg |= IO_PIP;
        !            27:        } else {
        !            28:                savchr  = cp[len];
        !            29:                cp[len] = 0;
        !            30:        }
        !            31: 
        !            32:        if ( ioptr -> flg & IO_PIP ) {
        !            33:                fd      = ospipe( ioptr );
        !            34:        } else if ( ioptr -> flg & IO_INP ) {
        !            35:                fd      = open( cp,0 );
        !            36:        } else {
        !            37:                if ( ioptr -> flg & IO_APP ) {
        !            38:                        fd      = open( cp,1 );
        !            39:                        if ( fd != 0 )
        !            40:                                lseek( fd,0,2 );
        !            41:                }
        !            42:                if ( fd < 0 )
        !            43:                        fd      = creat( cp,0666 );
        !            44:        }
        !            45: 
        !            46:        if ( !(ioptr -> flg & IO_PIP) )
        !            47:                cp[len] = savchr;
        !            48: 
        !            49:        if (fd > 0) {
        !            50:                ioptr -> fdn = fd;
        !            51:                ioptr -> flg |= IO_OPN;
        !            52:                if ( (ioptr -> flg & IO_INP) == 0 && testty( fd ) == 0 )
        !            53:                        ioptr -> flg |= IO_WRC;
        !            54:                if ( ioptr -> flg & IO_WRC )
        !            55:                        ioptr -> buf = 0;
        !            56:                return 0;
        !            57:        } else {
        !            58:                return -1;
        !            59:        }
        !            60: 
        !            61: }

unix.superglobalmegacorp.com

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