dup2() system call

Richard M. Mathews richard at locus.com
Tue Apr 23 11:44:06 AEST 1991


allbery at NCoast.ORG (Brandon S. Allbery KB8JRR/AA) writes:

>(Doug Gwyn's dup2() omitted)

>Reference's sake, yes --- but that was one that got some remarks about
>differing errno values.  (Which is why I had that remark in my comments.)

Actually, the problem with Gwyn's version is the behavior when, on entry
to the routine,
	newfd is a valid descriptor for an open file
	oldfd is not a valid descriptor for an open file
A real dup2 (as on V7) will return EBADF and leave newfd alone.
Gwyn's will return EBADF and close newfd.

>For almost every use of dup2() I've ever encountered, the macro does the job.
>If you absolutely NEED 100% V7 compatibility, use Doug's by all means.

I had problems with the super-simple-minded version of dup2 when porting
the BSD4.1 C Shell.  I don't remember if it was the above problem or the
problem with newfd==oldfd (I think it was the latter, and Gwyn's addresses
that).

Richard M. Mathews			Lietuva laisva = Free Lithuania
richard at locus.com			Brivu Latviju  = Free Latvia
lcc!richard at seas.ucla.edu		Eesti vabaks   = Free Estonia
...!{uunet|ucla-se|turnkey}!lcc!richard



More information about the Comp.unix.wizards mailing list