Annotation of researchv10no/cmd/spitbol/cint/osopen.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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