OPEN - open a file for read or write.

(Slightly different from UNIX function)

Usage:

#include <fildes.h>
#include <fcntl.h>
fd = open( name, flag [, mode ] );

Where:

char *name;
points to a string containing the name of the file to be opened.
int flag;
indicates various options for the open process. Names of the possible flags are listed below. The "flag" argument consists of one or more of these flags ORed together (e.g. with "|"). Note that the first three options are mutually exclusive.
O_RDONLY
open for reading only.
O_WRONLY
open for writing only.
O_RDWR
open for reading and writing.
O_APPEND
open for update at the end of the file.
O_CREAT
if O_RDWR is set, this causes the file to be created if it does not exist and truncated if it does. Without this flag, O_RDWR would expect the file to exist.
O_EXCL
if O_EXCL and O_CREAT are set, "open" will fail if the file exists and "errno" will be set to EEXIST. If the file does not exist, "open" will fail and "errno" will be set to EACCESS.
O_TRUNC
opens the file for writing. If the O_RDWR flag is set, the file is truncated to 0 or created if necessary.
int mode;
does nothing. It is simply accepted for compatibility with the UNIX "open" function.
int fd;
is a file descriptor number. This number will be between 0 and 19. The number is used in subsequent I/O processes for this file. If the operation fails, a -1 is returned and "errno" is set to indicate the error (see below).

Description:

"open" opens a file and returns a file descriptor number.

In GCOS batch, to open filecode 'XX', the filename "fc*XX" should be used.

Possible Errors:

errno=ENOENT
"name" was the NULL pointer.
errno=EACCES
"open" was unable to open the file.
errno=EEXIST
the file was successfully opened, but the O_CREAT and O_EXCL flags were both set. Because of this, the file was immediately closed again.

Notes:

The file descriptor I/O functions

close   creat   open   read   write

are supplied with SS mode C to simplify the task of porting programs from UNIX to GCOS-8. They provide a simulation of UNIX-style I/O primitives. However, they do NOT provide file access at a lower level than "fopen", "fclose", etc. In fact, the opposite is true.

If you wish to interweave calls to the "open" family of I/O functions with calls to the "fopen" family, you must be careful to use the "fdopen" and "fileno" functions for bridges between the two families. However, the "open" family will always be simulations, and imperfect ones at that. We strongly recommend that you use the ANSI standard functions instead of the UNIX pseudo-primitives.

See Also:

expl c lib fopen

expl c lib read

expl c lib write

expl c lib close

expl c lib fileno

expl c lib errno

expl c include fildes

Copyright © 1996, Thinkage Ltd.