How can I write an FPIPE() ?????

Paul Falstad pfalstad at phoenix.Princeton.EDU
Sat Feb 9 02:23:51 AEST 1991


djm at dmntor.UUCP (David McKellar) wrote:
>  pipe() returns those int file descriptors so I can't
>  use fprintf().  (sprintf() followed by write() is clumbsy!)
>
>  What I want is an fpipe() that does exactly the same as pipe
>  but returns type FILE.  Possible ?

Do a man on fdopen.

int fpipe(FILE *x[2])
{
int pipes[2];

   if (pipe(pipes) == -1)
      return -1;
   if (!(x[0] = fdopen(pipes[0],"r")))
      {
      close(pipes[0]);
      close(pipes[1]);
      return -1;
      }
   if (!(x[1] = fdopen(pipes[1],"w")))
      {
      fclose(x[0]);
      close(pipes[1]);
      return -1;
      }
   return 0;
}

--
Paul Falstad, pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
10 PRINT "PRINCETON CS"          | I think sexual ecstasy's overrated.
20 GOTO 10                       | [Your blood pressure just went up.]
Princeton University would like to apologize to everyone for this article.



More information about the Comp.unix.internals mailing list