1: /* Copyright (c) 1979 Regents of the University of California */
   2: #include    "stdio.h"
   3: #define tst(a,b) (*mode == 'r' ? (b) : (a))
   4: 
   5: FILE *
   6: popen(cmd,mode)
   7: char *cmd;
   8: char *mode;
   9: {
  10:     register i;
  11:     FILE *fptr;
  12:     struct pstruct {
  13:         int reader;
  14:         int writer;
  15:     } str;
  16: 
  17:     if (pipe(&str)<0) return NULL;
  18:     if ((i=fork())==0) {
  19:         close(tst(str.writer,str.reader));
  20:         close(tst(0,1));
  21:         dup(tst(str.reader,str.writer));
  22:         close(tst(str.reader,str.writer));
  23:         execl("/bin/sh","sh","-c",cmd,0);
  24:         exit(1);
  25:     }
  26:     if (i== -1) return NULL;
  27:     close(tst(str.reader,str.writer));
  28:     fptr=fopen("/dev/null",tst("w","r"));
  29:     setbuf(fptr,NULL);
  30:     fptr->_file=tst(str.writer,str.reader);
  31:     return fptr;
  32: }
  33: 
  34: pclose(ptr)
  35: FILE *ptr;
  36: {
  37:     int st;
  38: 
  39:     fclose(ptr);
  40:     wait(&st);
  41:     return st;
  42: }

Defined functions

pclose defined in line 34; used 1 times
popen defined in line 5; used 2 times

Defined struct's

pstruct defined in line 12; never used

Defined macros

tst defined in line 3; used 7 times
Last modified: 1980-09-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 663
Valid CSS Valid XHTML 1.0 Strict