open

NAME
SYNOPSIS
DESCRIPTION
COMMAND PIPELINES
SEE ALSO
KEYWORDS

______________________________________________________________________________

NAME

open - Open a file-based or command pipeline channel

SYNOPSIS

open fileName
open
fileName access
open
fileName access permissions _________________________________________________________________

DESCRIPTION

This command opens a file or command pipeline and returns a channel identifier that may be used in future invocations of commands like read, puts, and close. If the first character of fileName is not | then the command opens a file: fileName gives the name of the file to open, and it must conform to the conventions described in the filename manual entry.

The access argument, if present, indicates the way in which the file (or command pipeline) is to be accessed. In the first form access may have any of the following values:

r

Open the file for reading only; the file must already exist. This is the default value if access is not specified.

r+

Open the file for both reading and writing; the file must already exist.

w

Open the file for writing only. Truncate it if it exists. If it doesn’t exist, create a new file.

w+

Open the file for reading and writing. Truncate it if it exists. If it doesn’t exist, create a new file.

a

Open the file for writing only. The file must already exist, and the file is positioned so that new data is appended to the file.

a+

Open the file for reading and writing. If the file doesn’t exist, create a new empty file. Set the initial access position to the end of the file.

In the second form, access consists of a list of any of the following flags, all of which have the standard POSIX meanings. One of the flags must be either RDONLY, WRONLY or RDWR.

RDONLY

Open the file for reading only.

WRONLY

Open the file for writing only.

RDWR

Open the file for both reading and writing.

APPEND

Set the file pointer to the end of the file prior to each write.

CREAT

Create the file if it doesn’t already exist (without this flag it is an error for the file not to exist).

EXCL

If CREAT is also specified, an error is returned if the file already exists.

NOCTTY

If the file is a terminal device, this flag prevents the file from becoming the controlling terminal of the process.

NONBLOCK

Prevents the process from blocking while opening the file, and possibly in subsequent I/O operations. The exact behavior of this flag is system- and device-dependent; its use is discouraged (it is better to use the fconfigure command to put a file in nonblocking mode). For details refer to your system documentation on the open system call’s O_NONBLOCK flag.

TRUNC

If the file exists it is truncated to zero length.

If a new file is created as part of opening it, permissions (an integer) is used to set the permissions for the new file in conjunction with the process’s file mode creation mask. Permissions defaults to 0666.

COMMAND PIPELINES

If the first character of fileName is ’’|’’ then the remaining characters of fileName are treated as a list of arguments that describe a command pipeline to invoke, in the same style as the arguments for exec. In this case, the channel identifier returned by open may be used to write to the command’s input pipe or read from its output pipe, depending on the value of access. If write-only access is used (e.g. access is w), then standard output for the pipeline is directed to the current standard output unless overridden by the command. If read-only access is used (e.g. access is r), standard input for the pipeline is taken from the current standard input unless overridden by the command.

SEE ALSO

close(n), filename(n), gets(n), read(n), puts(n)

KEYWORDS

access mode, append, create, file, non-blocking, open, permissions, pipeline, process