add a missing section header table index conversion
[tangerine.git] / compiler / clib / dup2.c
blobc42d4fdb54b0e23c40c4462326ce8bc39476fc03
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function dup2().
6 */
8 #include <errno.h>
9 #include "__open.h"
11 /*****************************************************************************
13 NAME */
14 #include <unistd.h>
16 int dup2 (
18 /* SYNOPSIS */
19 int oldfd,
20 int newfd
23 /* FUNCTION
24 Duplicates a file descriptor.
26 The object referenced by the descriptor does not distinguish between oldd
27 and newd in any way. Thus if newd and oldd are duplicate references to
28 an open file, read(), write() and lseek() calls all move a single
29 pointer into the file, and append mode, non-blocking I/O and asynchronous
30 I/O options are shared between the references. If a separate pointer
31 into the file is desired, a different object reference to the file must be
32 obtained by issuing an additional open(2) call. The close-on-exec flag
33 on the new file descriptor is unset.
35 INPUTS
36 oldfd - The file descriptor to be duplicated
37 newfd - The value of the new descriptor we want the old one to be duplicated in
39 RESULT
40 -1 for error or newfd on success
42 NOTES
43 This function must not be used in a shared library or
44 in a threaded application.
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 accept(), open(), close(), fcntl(), pipe(), socket()
53 INTERNALS
55 ******************************************************************************/
57 fdesc *oldfdesc;
59 oldfdesc = __getfdesc(oldfd);
60 if (!oldfdesc)
62 errno = EBADF;
63 return -1;
66 newfd =__getfdslot(newfd);
67 if (newfd != -1)
69 oldfdesc->opencount++;
70 __setfdesc(newfd, oldfdesc);
73 return newfd;