home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / perl5a1.lha / perl5alpha1 / do / pipe < prev    next >
Encoding:
Text File  |  1992-08-15  |  947 b   |  53 lines

  1. #ifdef HAS_PIPE
  2. void
  3. do_pipe(TARG, rstab, wstab)
  4. STR *TARG;
  5. STAB *rstab;
  6. STAB *wstab;
  7. {
  8.     register STIO *rstio;
  9.     register STIO *wstio;
  10.     int fd[2];
  11.  
  12.     if (!rstab)
  13.     goto badexit;
  14.     if (!wstab)
  15.     goto badexit;
  16.  
  17.     rstio = stab_io(rstab);
  18.     wstio = stab_io(wstab);
  19.  
  20.     if (!rstio)
  21.     rstio = stab_io(rstab) = stio_new();
  22.     else if (rstio->ifp)
  23.     do_close(rstab,FALSE);
  24.     if (!wstio)
  25.     wstio = stab_io(wstab) = stio_new();
  26.     else if (wstio->ifp)
  27.     do_close(wstab,FALSE);
  28.  
  29.     if (pipe(fd) < 0)
  30.     goto badexit;
  31.     rstio->ifp = fdopen(fd[0], "r");
  32.     wstio->ofp = fdopen(fd[1], "w");
  33.     wstio->ifp = wstio->ofp;
  34.     rstio->type = '<';
  35.     wstio->type = '>';
  36.     if (!rstio->ifp || !wstio->ofp) {
  37.     if (rstio->ifp) fclose(rstio->ifp);
  38.     else close(fd[0]);
  39.     if (wstio->ofp) fclose(wstio->ofp);
  40.     else close(fd[1]);
  41.     goto badexit;
  42.     }
  43.  
  44.     str_sset(TARG,&str_yes);
  45.     return;
  46.  
  47. badexit:
  48.     str_sset(TARG,&str_undef);
  49.     return;
  50. }
  51. #endif
  52.  
  53.