Matthew Gregan wrote:
At 2005-01-12T13:51:54+1300, Carl Cerecke wrote:

Isn't that what dup2 is for?


For most cases, yes.  Without being able to close and reopen descriptor
0/1/2 there are still things you couldn't do using only dup2(), but the
only example I can think of right now isn't that great...

closing is not the problem, only opening is.

If you've closed, say, 2 and then want to reopen it, then you can:

close(2);
fd = open("foo","w");
if (dup2(fd,2) == -1) {
 // error
 quit();
}
close(fid);

Then you can fprintf(stderr,xxx) all you like.


Cheers, Carl.

Reply via email to