| 1 | #include <stdio.h> |
| 2 | FILE *_dofpip(iodes) |
| 3 | int iodes; |
| 4 | { |
| 5 | register FILE *p; |
| 6 | |
| 7 | for(p=_iob; (p->_flag&(_IOWRT|_IOREAD))!=0; p++) |
| 8 | if (p >= _iob+_NFILE) |
| 9 | return(NULL); |
| 10 | p->_file = iodes; |
| 11 | p->_cnt = 0; |
| 12 | p->_base = p->_ptr = NULL; |
| 13 | return(p); |
| 14 | } |
| 15 | |
| 16 | FILE * fpipe(info) |
| 17 | FILE *info[2]; |
| 18 | { |
| 19 | register FILE *p; |
| 20 | int descrips[2]; |
| 21 | |
| 22 | if(0 > pipe(descrips)) return( (FILE *) -1); |
| 23 | |
| 24 | if(NULL==(p = _dofpip(descrips[0]))) return( (FILE *) -1); |
| 25 | p->_flag = (_IONBF|_IOREAD); |
| 26 | info[0] = p; |
| 27 | |
| 28 | if(NULL==(p = _dofpip(descrips[1]))) return( (FILE *) -1); |
| 29 | p->_flag = _IOWRT; |
| 30 | info[1] = p; |
| 31 | return((FILE *) 2); /*indicate sucess*/ |
| 32 | } |