2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 ANSI C function dup2().
12 /*****************************************************************************
25 Duplicates a file descriptor.
27 The object referenced by the descriptor does not distinguish between oldd
28 and newd in any way. Thus if newd and oldd are duplicate references to
29 an open file, read(), write() and lseek() calls all move a single
30 pointer into the file, and append mode, non-blocking I/O and asynchronous
31 I/O options are shared between the references. If a separate pointer
32 into the file is desired, a different object reference to the file must be
33 obtained by issuing an additional open(2) call. The close-on-exec flag
34 on the new file descriptor is unset.
37 oldfd - The file descriptor to be duplicated
38 newfd - The value of the new descriptor we want the old one to be duplicated in
41 -1 for error or newfd on success
44 This function must not be used in a shared library or
45 in a threaded application.
52 bsdsocket.library/accept(), open(), close(), fcntl(), pipe()
53 bsdsocket.library/socket()
57 ******************************************************************************/
62 oldfdesc
= __getfdesc(oldfd
);
69 newfdesc
= __alloc_fdesc();
76 newfdesc
->fdflags
= 0;
77 newfdesc
->fcb
= oldfdesc
->fcb
;
79 newfd
=__getfdslot(newfd
);
82 newfdesc
->fcb
->opencount
++;
83 __setfdesc(newfd
, newfdesc
);