NAME
open - open for reading or writing
SYNOPSIS
#include <stdio_p.h>
#include <fcntl_p.h>
FD open(path, oflag[, mode])
char *path;
int oflag, mode;
DESCRIPTION
path
points to a path name naming a file on either the satellite system or
the host system (host path names are preceded with a '!'). Some path
names are reserved to open the local device drivers on the satellite.
A list of possible reserved names (depending on how the satellite is
configured) includes:
- /dev/tty
-
serial lines
- /dev/ck
-
programmable clock
- /dev/adc
-
analog to digital converter
- /dev/dac
-
digital to analog converter
- /dev/pk
-
packet driver
- /dev/sm
-
smpte time code
- /dev/rl
-
RL02 disk
- /dev/vd
-
visual display
- /dev/dk
-
display clock
- /dev/hco
-
high current digital output
- /dev/ttl
-
digit input and output
- /dev/ib
-
16-bit input buffer
See section 4 for a description of the function of these special
files.
open
opens a file descriptor for the named file and sets the file status
flags according to the value of
oflag. oflag
values are constructed by ORing flags from the following list:
Choose 1 from the next 3 permission flags.
- O_RDONLY
-
Open for reading only.
- O_WRONLY
-
Open for writing only.
- O_RDRW
-
Open for reading and writing.
- O_APPEND
-
If set, the file pointer will be set to the end of the file before the
first write.
- O_CREAT
-
If the file exists, this flag has no effect. If
path
refers to a host file, this file's owner ID is set to the process's
effective user ID, the file's group ID is set to the process's
effective group ID, and the low-order 12 bits of the file mode are set
to the value of
mode
modified by ORing together some combination of the following:
04000 set user ID on execution
02000 set groupo ID on execution
01000 save text image after execution
00400 read by owner
00200 write by owner
00100 execute (search on directory) by owner
00070 read, write, execute (search) by group
00007 read, write, execute (search) by others
If
path
refers to a satellite file, only the read/write/execute by owner
fields of
mode
are used.
- O_TRUNC
-
If the file exists, its length is truncated to 0 and the mode and
owner are unchanged.
- O_EXCL
-
If O_EXCL and O_CREAT are set,
open
will faile if the file exists.
Upon successful completions a non-negative integer, the file
descriptor, is returned.
The file pointer used to mark the current position within the file is
set to the beginning of the file, unless O_APPEND is set, in which
case the file pointer is set to the end of the file.
No process may have more than 20 host files or 10 satellite files open
simultaneously. Any number of special satellite devices may be open
at once.
The named file is opened unless one or more of the following are true:
-
A component of the path prefix is not a directory. [ENOTDIR]
-
O_CREAT is not set and the named files does not exist. [ENOENT]
-
A component of the path prefix denies search permission. [EACCES]
-
oflag
permission is denied for the named file. [EACCES]
-
The named file is a directory and
oflag
is write or read/write. [EISDIR]
-
The maximum file descriptors are currently open. [ENFILE]
-
The named file is a character special or block special file, and
the device associated with this special file does not exist. [ENXIO]
-
O_CREAT and O_EXCL are set, and the named file exists. [EEXIST]
RETURN VALUE
Upon successful completion, a non-negative integer, namely a file
descriptor, is returned. Otherwise, a value of -1 is returned and
errno
is set to indicate the error.
SEE ALSO
close(2P)
,
lseek(2P)
,
read(2P)
,
write(2P).