[Top] [Prev] [Next] [Bottom]


[Contents] [Index]

dup - duplicate an open file descriptor

dup: fn(oldfd, newfd: int): int;
## returns an integer file descriptor, or -1 if 
unsuccessful.

Description

The Limbo programming language and its libraries manage I/O via references to instances of an abstract data type, FD, called a file descriptor. This command duplicates an open file descriptor.

The dup function takes a valid integer file descriptor, oldfd, referring to an open file, and returns a new integer file descriptor referring to the same file. If newfd is in the range of legal file descriptors, dup will use that for the new file descriptor (closing any old file associated with newfd). If newfd is -1, the system chooses the lowest available file descriptor. If a suitable file descriptor cannot be found, dup returns -1.

Example

The following example opens the file descriptor output.fd (connected to the file outfile), then uses dup to replace it with 1, and assigns it to stdout.

output: ref sys->FD;
output = sys->open("outfile", sys->OWRITE);
stdout := sys->dup(output.fd, 1);

See Also

System Module Overview
open, create - open/create a file for reading or writing


[Top] [Prev] [Next] [Bottom]

infernosupport@lucent.com
Copyright © 1997, Lucent Technologies, Inc.. All rights reserved.