dup2.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <html>
  2. <head>
  3. <title>dup2</title>
  4. <body bgcolor=#ffffff>
  5. <h2 align=center>dup2</h2>
  6. <h4 align=center>OS/161 Reference Manual</h4>
  7. <h3>Name</h3>
  8. dup2 - clone file handles
  9. <h3>Library</h3>
  10. Standard C Library (libc, -lc)
  11. <h3>Synopsis</h3>
  12. #include &lt;unistd.h&gt;<br>
  13. <br>
  14. int<br>
  15. dup2(int <em>oldfd</em>, int <em>newfd</em>);
  16. <h3>Description</h3>
  17. dup2 clones the file handle <em>oldfd</em> onto the file handle
  18. <em>newfd</em>. If <em>newfd</em> names an open file, that file is
  19. closed.
  20. <p>
  21. The two handles refer to the same "open" of the file - that is,
  22. they are references to the same object and share the same seek
  23. pointer. Note that this is different from opening the same file
  24. twice.
  25. <p>
  26. dup2 is most commonly used to relocate opened files onto
  27. STDIN_FILENO, STDOUT_FILENO, and/or STDERR_FILENO.
  28. <p>
  29. Both filehandles must be non-negative.
  30. <p>
  31. Using dup2 to clone a file handle onto itself has no effect.
  32. <p>
  33. (The "2" in "dup2" arises from the existence of an older and less
  34. powerful Unix system call "dup".)
  35. <h3>Return Values</h3>
  36. dup2 returns <em>newfd</em>. On error, -1 is returned, and
  37. <A HREF=errno.html>errno</A> is set according to the error
  38. encountered.
  39. <h3>Errors</h3>
  40. The following error codes should be returned under the conditions
  41. given. Other error codes may be returned for other errors not
  42. mentioned here.
  43. <blockquote><table width=90%>
  44. <tr><td width=10%>&nbsp;</td><td>&nbsp;</td></tr>
  45. <tr><td>EBADF</td> <td><em>oldfd</em> is not a valid file handle,
  46. or <em>newfd</em> is a value that
  47. cannot be a valid file handle.</td></tr>
  48. <tr><td>EMFILE</td> <td>The process's file table was full, or a
  49. process-specific limit on open files
  50. was reached.</td></tr>
  51. </table></blockquote>
  52. </body>
  53. </html>