[net.unix-wizards] What is the dup2

espo@bpa.UUCP (11/08/83)

	I know that a while ago, someone defined what the dup2() command
	does.  UNIX 4.0 USG doesn't have this available within it's
	repertoire.  Can someone answer ??



	Thanks in advance,

	Bob Esposito...bpa!espo

jreuter@cincy.UUCP (11/12/83)

In UNIX 4.0USG, the dup2() system call should be replaced with the
fcntl( fildes, F_DUPFD, arg ) system call if 4.0USG is anything like
the released system III.

	Jim Reuter
	(decvax!cincy!jreuter)

nrf@whuxle.UUCP (11/20/83)

#R:bpa:-19200:whuxle:20900001:000:290
whuxle!npl    Nov 10 00:38:00 1983

I happen to be looking at the page for dup(2) in a
5.0 manual right now.  It's there.  There are just too many
programs which will break (including the shell) if you
remove this system call.  Not wixhing to be facetious,
but mayhaps our manual has a page missing?

				...!harpo!whuxle!npl

-- 
Neal Fildes
A.T.&T. - Bell Laboratories
Whippany, NJ, U.S.A.

donn@hp-dcd.UUCP (11/23/83)

#R:bpa:-19200:hp-dcd:3200004:000:408
hp-dcd!donn    Nov 16 09:42:00 1983

On dup2().

A emulation using fcntl and F_DUPFD was suggested, but it doesn't always
work.  If you read dup2() documentation carefully it does a dup to
*exactly* its argument, doing a close if necessary.  Fcntl does it to
the first available slot >= its argument.  Thus the suggested emulation
doesn't always work.  The emulation is:

	close(arg);
	fcntl(fd, F_DUPFD, arg);

Donn Terry
...hplabs!hp-dcd!donn