126 lines
3.1 KiB
HTML
126 lines
3.1 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>dup(2)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>dup(2)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
dup, dup2 - duplicate a descriptor
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><unistd.h></STRONG>
|
|
|
|
<STRONG>int</STRONG> <STRONG>dup(int</STRONG> <EM>oldd</EM><STRONG>)</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>dup2(int</STRONG> <EM>oldd</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>newd</EM><STRONG>)</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
<STRONG>Dup</STRONG> duplicates an existing descriptor. The argument <EM>oldd</EM> is a small non-
|
|
negative integer index in the per-process descriptor table. The value
|
|
must be less than OPEN_MAX, the size of the table. The new descriptor
|
|
returned by the call, let's name it <EM>newd</EM>, is the lowest numbered
|
|
descriptor that is not currently in use by the process.
|
|
|
|
The object referenced by the descriptor does not distinguish between
|
|
references using <EM>oldd</EM> and <EM>newd</EM> in any way. Thus if <EM>newd</EM> and <EM>oldd</EM> are
|
|
duplicate references to an open file, <STRONG><A HREF="../man2/read.2.html">read(2)</A></STRONG>, <STRONG><A HREF="../man2/write.2.html">write(2)</A></STRONG> and <STRONG><A HREF="../man2/lseek.2.html">lseek(2)</A></STRONG>
|
|
calls all move a single pointer into the file, and append mode, non-
|
|
blocking I/O and asynchronous I/O options are shared between the
|
|
references. If a separate pointer into the file is desired, a different
|
|
object reference to the file must be obtained by issuing an additional
|
|
<STRONG><A HREF="../man2/open.2.html">open(2)</A></STRONG> call. The close-on-exec flag on the new file descriptor is
|
|
unset.
|
|
|
|
In the second form of the call, the value of <EM>newd</EM> desired is specified.
|
|
If this descriptor is already in use, the descriptor is first deallocated
|
|
as if a <STRONG><A HREF="../man2/close.2.html">close(2)</A></STRONG> call had been done first. <EM>Newd</EM> is not closed if it
|
|
equals <EM>oldd</EM>.
|
|
|
|
|
|
</PRE>
|
|
<H2>RETURN VALUE</H2><PRE>
|
|
The value -1 is returned if an error occurs in either call. The external
|
|
variable <STRONG>errno</STRONG> indicates the cause of the error.
|
|
|
|
|
|
</PRE>
|
|
<H2>ERRORS</H2><PRE>
|
|
<STRONG>Dup</STRONG> and <STRONG>dup2</STRONG> fail if:
|
|
|
|
[EBADF] <EM>Oldd</EM> or <EM>newd</EM> is not a valid active descriptor
|
|
|
|
[EMFILE] Too many descriptors are active.
|
|
|
|
|
|
</PRE>
|
|
<H2>NOTES</H2><PRE>
|
|
<STRONG>Dup</STRONG> and <STRONG>dup2</STRONG> are now implemented using the <STRONG>F_DUPFD</STRONG> function of <STRONG><A HREF="../man2/fcntl.2.html">fcntl(2)</A></STRONG>,
|
|
although the old system call interfaces still exist to support old
|
|
programs.
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man2/open.2.html">open(2)</A></STRONG>, <STRONG><A HREF="../man2/close.2.html">close(2)</A></STRONG>, <STRONG><A HREF="../man2/fcntl.2.html">fcntl(2)</A></STRONG>, <STRONG><A HREF="../man2/pipe.2.html">pipe(2)</A></STRONG>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|