Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (2) — Plan9 3rd Edition (Vita Nuova)

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sys-intro(2)

sys-open(2)

SYS-DUP(2)

NAME

dup − duplicate an open file descriptor

SYNOPSIS

include "sys.m";
sys := load Sys Sys->PATH;
 dup:    fn(oldfd, newfd: int):  int;
fildes: fn(fd: int):            ref FD;

DESCRIPTION

The Limbo programming language and its libraries manage I/O via references to instances of abstract data type, FD, called a Limbo file descriptor, or simply ‘file descriptor’ when the context is understood. ­FD holds an integer-valued file descriptor, the form used by the operating system, in a structure that can be reference counted and garbage collected.  There are occasions when a program must access the underlying integer file descriptor, such as when rearranging the standard input and output for a new subprocess. 

The ­dup call 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. 

­Fildes uses the integer file descriptor ­fd to create a new Limbo file descriptor, suitable for other ­Sys module functions.  It returns ­nil if it cannot convert fd.

SEE ALSO

sys-intro(2), sys-open(2)

Plan 9  —  June 29, 2000

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