Go to the previous, next section.

creat and open

SYNOPSIS

int open(const char *path, int flags);

int open(const char *path, int flags, mode_t mode);

int creat(const char *path, mode_t mode);

PARAMETERS

path: [in] the path of the new file to create.

mode: [in] the new permission mask of the file. It is masked by the umask value: (mode & ~umask).

flags: [in] flags (see description).

DESCRIPTION

open opens an file. The flags parameter must be one 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.

The following values may be or'ed together and with one of the preceding values:

O_CREAT
create the file if it does not exist.

O_EXCL
used with O_CREAT, if the file exists, the call fails. The test for existence and the creation if the file does not exists is atomic operation according to POSIX.1.

O_NOCTTY
the file will not become the controly tty of the task even if the file is a tty and the task does not have a controling terminal.

O_TRUNC
if the file already exists, truncate its lenght to 0.

O_APPEND
the file is opened for appending. The file pointer is always at the end of the file.

O_NONBLOCK or O_NDELAY
the calls manipulating the file never block.

O_SYNC
the file buffers are always synchronized with the on disk file. The write calls block until the data is completely written on disk. This is not POSIX.1.
create creates a new file. The new file is open for writing only. If a file with the same path already existed, then it is trucated.

RETURN VALUE

On success, a file descriptor for the file is returned. This file descriptor is the lowest numbered unused descriptor. On error, those calls return -1, and errno is set to one of the following values.

Go to the previous, next section.