V7/usr/man/man2/dup.2

Find at most related files.
including files from this version of Unix.

.TH DUP 2 
.SH NAME
dup, dup2 \- duplicate an open file descriptor
.SH SYNOPSIS
.B dup(fildes)
.br
.B int fildes;
.PP
.B dup2(fildes, fildes2)
.br
.B int fildes, fildes2;
.SH DESCRIPTION
Given
a file descriptor returned from
an
.I open,
.I pipe,
or
.I creat
call,
.I dup
allocates another file descriptor
synonymous
with
the original.
The new file descriptor is returned.
.PP
In the second form of the call,
.I fildes
is a file descriptor referring to an open file, and
.I fildes2
is a non-negative integer less than the maximum value
allowed for file descriptors (approximately 19).
.I Dup2
causes
.I fildes2
to refer to the same file as
.I fildes.
If
.I fildes2
already referred to an open file, it is closed first.
.SH "SEE ALSO"
creat(2), open(2), close(2), pipe(2)
.SH DIAGNOSTICS
The value \-1 is returned if:
the given file descriptor is invalid;
there are already too many open files.
.SH ASSEMBLER
(dup = 41.)
.br
(file descriptor in r0)
.br
(new file descriptor in r1)
.br
.B sys dup
.br
(file descriptor in r0)
.PP
The
.I dup2
entry is implemented by adding 0100 to
.I fildes.