51 lines
994 B
Groff
51 lines
994 B
Groff
.TH DUP 2
|
|
.UC 4
|
|
.SH NAME
|
|
dup, dup2 \- duplicate fildescriptors
|
|
.SH SYNOPSIS
|
|
.nf
|
|
.B #include<unistd.h>
|
|
.B int dup (int fildes);
|
|
.B int dup2 (int old, int new);
|
|
.fi
|
|
.SH DESCRIPTION
|
|
.B dup()
|
|
duplicates the filedescriptor
|
|
.I filedes
|
|
and returns either the duplicated file descriptor.
|
|
.PP
|
|
.B dup2()
|
|
duplicates the file descriptor
|
|
.I old,
|
|
and returns a new file descriptor with a value equal to
|
|
.I newfd.
|
|
If
|
|
.I newfd
|
|
was open, it is closed before duplication.
|
|
.PP
|
|
.B dup()
|
|
and
|
|
.B dup2()
|
|
both return negative values on error.
|
|
.SH ERRORS
|
|
.B -EBADF
|
|
is returned when an bad file descriptor is passed to either,
|
|
for the original file descriptor
|
|
that is being duplicated.
|
|
.PP
|
|
.B -EINVAL
|
|
is returned by
|
|
.B dup2()
|
|
when an invalid
|
|
.I new
|
|
descriptor is passed.
|
|
.PP
|
|
.B -EMFILE
|
|
is returned when the system runs out of file descriptors. See
|
|
.B open(2)
|
|
for a discussion on how to circumvent this.
|
|
.SH FILES
|
|
linux/fs/fcntl.c, /usr/include/linux/sys.h, /usr/include/unistd.h
|
|
.SH SEE ALSO
|
|
open(2)
|