Scheme 48 Manual | Contents | In Chapter: Access to POSIX
Previous: Time | Next: Regular expressions


These procedures are in structures posix-i/o and posix.

Open-pipe creates a new pipe and returns the two ends as an input port and an output port.

A file descriptor port (or fd-port) is a port that reads to or writes from an OS file descriptor. Fd-ports are returned by open-input-file, open-output-file, open-file, open-pipe, and other procedures.

Fd-port? returns true if its argument is an fd-port. Port->fd returns the file descriptor associated with or #f if port is not an fd-port. Remap-file-descriptors reassigns file descriptors to ports. The fd-specs indicate which port is to be mapped to each file descriptor: the first gets file descriptor 0, the second gets 1, and so forth. A fd-spec is either a port that reads from or writes to a file descriptor, or #f, with #f indicating that the corresponding file descriptor is not used. Any open ports not listed are marked `close-on-exec'. The same port may be moved to multiple new file descriptors.

For example,

(remap-file-descriptors (current-output-port)
moves the current output port to file descriptor 0 and the current input port to file descriptor 2. These change fd-port's file descriptor and return a new port that uses ports's old file descriptor. Dup uses the lowest unused file descriptor and dup2 uses the one provided. Dup-switching-mode is the same as dup except that the returned port is an input port if the argument was an output port and vice versa. If any existing port uses the file descriptor passed to dup2, that port is closed. Close-all-but closes all file descriptors whose associated ports are not passed to it as arguments. Close-on-exec? returns true if port will be closed when a new program is exec'ed. Set-close-on-exec?! sets port's close-on-exec flag. These two procedures read and write various options for port. The options that can be read are append, nonblocking, read-only, write-only, and read/write. Only the append and nonblocking can be written. Port-is-a-terminal? returns true if port has an underlying file descriptor that is associated with a terminal. For such ports port-terminal-name returns the name of the terminal, for all others it returns #f.

Previous: Time | Next: Regular expressions