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

1.1       root        1: 
                      2: 
                      3: 
                      4: /*
                      5:        ospipe( ioptr ) builds a pipe for the input association.
                      6:        the value returned is the file descriptor.
                      7: */
                      8: 
                      9: #include "spitblks.h"
                     10: #include "spitio.h"
                     11: 
                     12: ospipe( ioptr )
                     13: 
                     14: struct ioblk   *ioptr;
                     15: 
                     16: {
                     17:        int     childfd, childpid, fd[2], len, parentfd, status;
                     18:        char    *cp;
                     19:        struct  scblk   *scptr;
                     20: 
                     21:        if ( (status = pipe( fd )) < 0 )
                     22:                return -1;
                     23: 
                     24:        if ( ioptr -> flg & IO_INP ) {
                     25:                parentfd = fd[0];
                     26:                childfd  = fd[1];
                     27:        } else {
                     28:                parentfd = fd[1];
                     29:                childfd  = fd[0];
                     30:        }
                     31: 
                     32:        switch ( childpid = fork() ) {
                     33: 
                     34:                case -1:
                     35:                        close( parentfd );
                     36:                        close( childfd );
                     37:                        parentfd = -1;
                     38:                        break;
                     39: 
                     40:                case 0:
                     41:                        if ( ioptr -> flg & IO_INP )
                     42:                                close( 1 );
                     43:                        else
                     44:                                close( 0 );
                     45:                        dup( childfd );
                     46:                        for ( childfd = 3; childfd <= 32; close( childfd++ ));
                     47:                        scptr = ioptr -> fnm;
                     48:                        cp    = scptr -> str;
                     49:                        len   = lenfnm( scptr );
                     50:                         cp[len] = '\0';
                     51:                        if ( cp[len - 1] == cp[1] )
                     52:                                 cp[len - 1] = ' ';
                     53:                         cp[1] = ' ';
                     54:                         cp[0] = ' ';
                     55:                        execl( "/bin/sh","sh","-c",cp,0 );
                     56:                        break;
                     57: 
                     58:                default:
                     59:                        ioptr -> pid = childpid;
                     60:                        close( childfd );
                     61:                        break;
                     62:        }
                     63: 
                     64:        return parentfd;
                     65: 
                     66: }
                     67: 
                     68: 

unix.superglobalmegacorp.com

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