dup2
Root Boy Jim
rbj at uunet.UU.NET
Wed Feb 13 09:37:12 AEST 1991
In article <richard.666334818 at fafnir.la.locus.com> richard at locus.com (Richard M. Mathews) writes:
>I have not yet seen a correct version of code for dup2() posted. The
>versions posted by Paul Falsted, Doug Gwyn, and Root Boy Jim all fail
>the following test case because they close "fd2" too soon:
I suppose it depend on your interpretation. If you try dup2(-1,fileno(stdout))
and end up with nowhere to print to, have you not made a copy of your
input file descriptor? What does the shell do with "cmd >&- 2>&1"?
And what is the "meaning" of dup2(1,1)? Anyone who trys to do this
probably has a logic error somewhere, regardless of the definition.
In any case, I am willing to add "if (new == old) return(new);" to my code.
I also claim that I handled errno properly. It is not necessary
to preserve the old value of errno if dup2 returns true.
And Guy, you are right, any system that has neither dup2 nor fcntl
probably has lots of problems. However, my version works in V6!
--
[rbj at uunet 1] stty sane
unknown mode: sane
More information about the Comp.unix.internals
mailing list