source: trunk/minix/man/man2/dup.2@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 2.1 KB
Line 
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
10dup, dup2 \- duplicate a descriptor
11.SH SYNOPSIS
12.nf
13.ft B
14#include <unistd.h>
15
16int dup(int \fIoldd\fP)
17int dup2(int \fIoldd\fP, int \fInewd\fP)
18.SH DESCRIPTION
19.B Dup
20duplicates an existing descriptor.
21The argument \fIoldd\fP is a small non-negative integer index in
22the per-process descriptor table. The value must be less
23than OPEN_MAX, the size of the table.
24The new descriptor returned by the call, let's name it
25.I newd,
26is the lowest numbered descriptor that is
27not currently in use by the process.
28.PP
29The object referenced by the descriptor does not distinguish
30between references using \fIoldd\fP and \fInewd\fP in any way.
31Thus if \fInewd\fP and \fIoldd\fP are duplicate references to an open
32file,
33.BR read (2),
34.BR write (2)
35and
36.BR lseek (2)
37calls all move a single pointer into the file,
38and append mode, non-blocking I/O and asynchronous I/O options
39are shared between the references.
40If a separate pointer into the file is desired, a different
41object reference to the file must be obtained by issuing an
42additional
43.BR open (2)
44call.
45The close-on-exec flag on the new file descriptor is unset.
46.PP
47In the second form of the call, the value of
48.IR newd
49desired is specified. If this descriptor is already
50in use, the descriptor is first deallocated as if a
51.BR close (2)
52call had been done first.
53.I Newd
54is not closed if it equals
55.IR oldd .
56.SH "RETURN VALUE
57The value \-1 is returned if an error occurs in either call.
58The external variable
59.B errno
60indicates the cause of the error.
61.SH "ERRORS
62.B Dup
63and
64.B dup2
65fail if:
66.TP 15
67[EBADF]
68\fIOldd\fP or
69\fInewd\fP is not a valid active descriptor
70.TP 15
71[EMFILE]
72Too many descriptors are active.
73.SH NOTES
74.B Dup
75and
76.B dup2
77are now implemented using the
78.B F_DUPFD
79function of
80.BR fcntl (2),
81although the old system call interfaces still exist to support old programs.
82.SH "SEE ALSO"
83.BR open (2),
84.BR close (2),
85.BR fcntl (2),
86.BR pipe (2).
Note: See TracBrowser for help on using the repository browser.