dup2

Richard M. Mathews richard at locus.com
Tue Feb 12 16:00:18 AEST 1991


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:
	main()
	{
		dup2(-1,fileno(stdout));  /* this returns -1 as expected */
		printf("stdout *should* still be OK\n");
	}
Only the version posted by Chet Ramey gets this right, but only Doug
Gwyn's version does everything right with errno, including mapping
EINVAL to EBADF.

I would post what I consider to be the right answer, but I have licensing
problems.  I can recommend taking ideas from both Gwyn and Ramey; perhaps
one of them would be willing to post the result of such a merge.

Richard M. Mathews			 Freedom for Lithuania
richard at locus.com				Laisve!
lcc!richard at seas.ucla.edu
...!{uunet|ucla-se|turnkey}!lcc!richard



More information about the Comp.unix.wizards mailing list