Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ dup(2) — Ultrix-11 3.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

creat(2)

exec(2)

fcntl(2)

open(2)

pipe(2)

dup(2)

NAME

dup, dup2 − duplicate an open file descriptor

SYNTAX

int dup(fildes)
int fildes;

int dup2(fildes, fildes2)
int fildes, fildes2;

DESCRIPTION

Given a file descriptor returned from a creat open, or pipe, call, the dup system call allocates another file descriptor that is identical with the original. 

In the dup2 call, the fildes argument is a file descriptor referring to an open file, and the fildes2 argument is a non-negative integer less than the maximum value allowed for file descriptors (19).  The dup2 call causes fildes2 to refer to the same file as fildes.  If fildes2 already referred to an open file, it is closed first. 

RETURN VALUE

If successful, returns a new file descriptor.  If unsuccessful, returns a −1, and the global variable errno indicates the error code. 

DIAGNOSTICS

Both dup and dup2 calls will fail if:

[EBADF] Either fildes or fildes2 is not a valid active descriptor. 

[EMFILE] Too many descriptors (20) are active. 

ASSEMBLER

(dup = 41.) 
(file descriptor in r0)
(new file descriptor in r1)
sys dup
(file descriptor in r0)

The dup2 entry is implemented by adding 0100 to fildes. 

SEE ALSO

close(2), creat(2), exec(2), fcntl(2), open(2), pipe(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026