📄 dup.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>dup</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_003_178"> </a>NAME</h4><blockquote>dup, dup2 - duplicate an open file descriptor</blockquote><h4><a name = "tag_000_003_179"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="unistd.h.html">unistd.h</a>>int dup(int <i>fildes</i>);int dup2(int <i>fildes</i>, int <i>fildes2</i>);</code></pre></blockquote><h4><a name = "tag_000_003_180"> </a>DESCRIPTION</h4><blockquote>The<i>dup()</i>and<i>dup2()</i>functions provide an alternative interface to the service provided by<i><a href="fcntl.html">fcntl()</a></i>using the F_DUPFD command. The call:<pre><code>fid = dup(<i>fildes</i>);</code></pre>is equivalent to:<pre><code>fid = fcntl(<i>fildes</i>, F_DUPFD, 0);</code></pre>The call:<pre><code>fid = dup2(<i>fildes</i>, <i>fildes2</i>);</code></pre>is equivalent to:<pre><code>close(<i>fildes2</i>);fid = fcntl(<i>fildes</i>, F_DUPFD, <i>fildes2</i>);</code></pre>except for the following:<ul><p><li>If<i>fildes2</i>is less than 0 or greater than or equal to {OPEN_MAX},<i>dup2()</i>returns -1 with<i>errno</i>set to [EBADF].<p><li>If<i>fildes</i>is a valid file descriptor and is equal to<i>fildes2</i>,<i>dup2()</i>returns<i>fildes2</i>without closing it.<p><li>If<i>fildes</i>is not a valid file descriptor,<i>dup2()</i>returns -1 and does not close<i>fildes2</i>.<p><li>The value returned is equal to the value of<i>fildes2</i>upon successful completion, or is -1 upon failure.<p></ul></blockquote><h4><a name = "tag_000_003_181"> </a>RETURN VALUE</h4><blockquote>Upon successful completion a non-negative integer, namely the file descriptor,is returned. Otherwise, -1 is returned and<i>errno</i>is set to indicate the error.</blockquote><h4><a name = "tag_000_003_182"> </a>ERRORS</h4><blockquote>The<i>dup()</i>function will fail if:<dl compact><dt>[EBADF]<dd>The<i>fildes</i>argument is not a valid open file descriptor.<dt>[EMFILE]<dd>The number of file descriptors in use by this process would exceed {OPEN_MAX}.</dl><p>The<i>dup2()</i>function will fail if:<dl compact><dt>[EBADF]<dd>The<i>fildes</i>argument is not a valid open file descriptor or the argument<i>fildes2</i>is negative or greater than or equal to{OPEN_MAX} .<dt>[EINTR]<dd>The<i>dup2()</i>function was interrupted by a signal.</dl></blockquote><h4><a name = "tag_000_003_183"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_003_184"> </a>APPLICATION USAGE</h4><blockquote>None.</blockquote><h4><a name = "tag_000_003_185"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_003_186"> </a>SEE ALSO</h4><blockquote><i><a href="close.html">close()</a></i>,<i><a href="fcntl.html">fcntl()</a></i>,<i><a href="open.html">open()</a></i>,<i><a href="unistd.h.html"><unistd.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 1 of the SVID.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -