.th dup IV 4/21/86
.sh NAME
dup - duplicate an open file descriptor
.sh SYNOPSIS
dup(fildes)
.br
int fildes;
.ft R
.sh DESCRIPTION
Given a file descriptor returned from an open, pipe, creat, or port
call, dup will allocate another file descriptor synonymous with the
original.  The new file descriptor is returned.
.s3
Dup is used more to reassign the value of file descriptors than to
genuinely duplicate a file descriptor.  Since the algorithm to allocate
file descriptors returns the lowest available value, combinations of
dup and close can be used to manipulate file descriptors in a general
way.  This is handy for manipulating standard input and/or standard
output.
.sh "SEE ALSO"
creat (IV), open (IV), close (IV), pipe (IV)
.sh DIAGNOSTICS
The error bit (c-bit) is set if: the given file descriptor is invalid;
there are already too many open files.  From C, a -1 returned value
indicates an error.
.sh KSOS
