Go to the first, previous, next, last section, table of contents.


open

Syntax

#include <fcntl.h>
#include <sys/stat.h> /* for mode definitions */

int open(const char *file, int mode /*, int permissions */);

Description

This function opens the named file in the given mode, which is any combination of the following:

O_RDONLY
The file is opened for reading.
O_WRONLY
The file is opened for writing.
O_RDWR
The file is opened for both reading and writing.
O_CREAT
If the file does not exist, it is created. See section creat.
O_TRUNC
If the file does exist, it is truncated to zero bytes.
O_EXCL
If the file exists, and O_CREAT is also specified, the open call will fail.
O_APPEND
The file pointer is positioned at the end of the file before each write.
O_TEXT
The file is opened in text mode, meaning that Ctrl-M characters are stripped on reading and added on writing as needed. The default mode is specified by the _fmode variable section _fmode.
O_BINARY
The file is opened in binary mode. When called to open the console in binary mode, open will disable the generation of SIGINT when you press Ctrl-C (Ctrl-Break will still cause SIGINT), because many programs that use binary reads from the console will also want to get the `^C' characters. You can use the __djgpp_set_ctrl_c library function (see section __djgpp_set_ctrl_c) if you want Ctrl-C to generate interrupts while console is read in binary mode.

If the file is created by this call, it will be given the read/write permissions specified by permissions, which may be any combination of these values:

S_IRUSR
The file is readable. This is always true for MS-DOS.
S_IWUSR
The file is writable.

Other S_I* values may be included, but they will be ignored.

You can specify the share flags (a DOS specific feature) in mode. And you can indicate default values for the share flags in __djgpp_share_flags. See section __djgpp_share_flags.

Return Value

If successful, the file descriptor is returned. On error, a negative number is returned and errno is set to indicate the error.

Portability

not ANSI, POSIX

Example

int q = open("/tmp/foo.dat", O_RDONLY|O_BINARY);


Go to the first, previous, next, last section, table of contents.