free the correctly allocated size
[AROS.git] / compiler / posixc / dup.c
blob06c18c88db630cd0ba959f36b0734888e8c4244c
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function dup().
6 */
8 #include <errno.h>
9 #include "__fdesc.h"
11 /*****************************************************************************
13 NAME */
14 #include <unistd.h>
16 int dup (
18 /* SYNOPSIS */
19 int oldfd
22 /* FUNCTION
23 Duplicates a file descriptor.
25 The object referenced by the descriptor does not distinguish between oldd
26 and newd in any way. Thus if newd and oldd are duplicate references to
27 an open file, read(), write() and lseek() calls all move a single
28 pointer into the file, and append mode, non-blocking I/O and asynchronous
29 I/O options are shared between the references. If a separate pointer
30 into the file is desired, a different object reference to the file must be
31 obtained by issuing an additional open(2) call. The close-on-exec flag
32 on the new file descriptor is unset.
34 INPUTS
35 oldfd - The file descriptor to be duplicated
37 RESULT
38 -1 for error or the new descriptor.
40 The new descriptor returned by the call is the lowest numbered
41 descriptor currently not in use by the process.
43 NOTES
44 This function must not be used in a shared library or
45 in a threaded application.
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 bsdsocket.library/accept(), open(), close(), fcntl(), pipe()
53 bsdsocket.library/socket()
55 INTERNALS
57 ******************************************************************************/
59 return dup2(oldfd, __getfirstfd(0));