dup 827 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. .TH DUP 2
  2. .SH NAME
  3. dup \- duplicate an open file descriptor
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .B
  10. int dup(int oldfd, int newfd)
  11. .SH DESCRIPTION
  12. Given a file descriptor,
  13. .IR oldfd ,
  14. referring to an open file,
  15. .I dup
  16. returns a new file descriptor referring to the same file.
  17. .PP
  18. If
  19. .I newfd
  20. is \-1 the system chooses the lowest available file descriptor.
  21. Otherwise,
  22. .I dup
  23. will use
  24. .I newfd
  25. for the new file descriptor
  26. (closing any old file associated with
  27. .IR newfd ).
  28. File descriptors are allocated dynamically,
  29. so to prevent unwarranted growth of the file descriptor table,
  30. .I dup
  31. requires that
  32. .I newfd
  33. be no greater than 20 more than the highest file descriptor ever used by
  34. the program.
  35. .SH SOURCE
  36. .B /sys/src/libc/9syscall
  37. .SH SEE ALSO
  38. .IR intro (2),
  39. .IR dup (3)
  40. .SH DIAGNOSTICS
  41. Sets
  42. .IR errstr .