|
|
1.1 ! root 1: .\" Copyright (c) 1980 Regents of the University of California. ! 2: .\" All rights reserved. The Berkeley software License Agreement ! 3: .\" specifies the terms and conditions for redistribution. ! 4: .\" ! 5: .\" @(#)dup.2 6.3 (Berkeley) 5/13/86 ! 6: .\" ! 7: .TH DUP 2 "May 13, 1986" ! 8: .UC 4 ! 9: .SH NAME ! 10: dup, dup2 \- duplicate a descriptor ! 11: .SH SYNOPSIS ! 12: .nf ! 13: .ft B ! 14: newd = dup(oldd) ! 15: int newd, oldd; ! 16: .PP ! 17: .ft B ! 18: dup2(oldd, newd) ! 19: int oldd, newd; ! 20: .fi ! 21: .SH DESCRIPTION ! 22: .I Dup ! 23: duplicates an existing object descriptor. ! 24: The argument \fIoldd\fP is a small non-negative integer index in ! 25: the per-process descriptor table. The value must be less ! 26: than the size of the table, which is returned by ! 27: .IR getdtablesize (2). ! 28: The new descriptor returned by the call, ! 29: .I newd, ! 30: is the lowest numbered descriptor that is ! 31: not currently in use by the process. ! 32: .PP ! 33: The object referenced by the descriptor does not distinguish ! 34: between references using \fIoldd\fP and \fInewd\fP in any way. ! 35: Thus if \fInewd\fP and \fIoldd\fP are duplicate references to an open ! 36: file, ! 37: .IR read (2), ! 38: .IR write (2) ! 39: and ! 40: .IR lseek (2) ! 41: calls all move a single pointer into the file, ! 42: and append mode, non-blocking I/O and asynchronous I/O options ! 43: are shared between the references. ! 44: If a separate pointer into the file is desired, a different ! 45: object reference to the file must be obtained by issuing an ! 46: additional ! 47: .IR open (2) ! 48: call. ! 49: The close-on-exec flag on the new file descriptor is unset. ! 50: .PP ! 51: In the second form of the call, the value of ! 52: .IR newd ! 53: desired is specified. If this descriptor is already ! 54: in use, the descriptor is first deallocated as if a ! 55: .IR close (2) ! 56: call had been done first. ! 57: .SH "RETURN VALUE ! 58: The value \-1 is returned if an error occurs in either call. ! 59: The external variable ! 60: .I errno ! 61: indicates the cause of the error. ! 62: .SH "ERRORS ! 63: .I Dup ! 64: and ! 65: .I dup2 ! 66: fail if: ! 67: .TP 15 ! 68: [EBADF] ! 69: \fIOldd\fP or ! 70: \fInewd\fP is not a valid active descriptor ! 71: .TP 15 ! 72: [EMFILE] ! 73: Too many descriptors are active. ! 74: .SH "SEE ALSO" ! 75: accept(2), ! 76: open(2), ! 77: close(2), ! 78: fcntl(2), ! 79: pipe(2), ! 80: socket(2), ! 81: socketpair(2), ! 82: getdtablesize(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.