int open(int dir_fd, char *path, int path_len, int flags);
open
opens the passed file relative to dir_fd
, depending on the
flags passed. It does not create the file if not existent. By default, the file
descriptor will remain open across an exec
.
flags
can be an OR’d field of the following elements:
O_RDONLY (0b0000001)
Makes the file able to be read.
O_WRONLY (0b0000010)
Makes the file able to be written to.
O_APPEND (0b0000100)
Makes the file be opened at the end of the file, instead of the beginning.
O_CLOEXEC (0b0001000)
Will make the file close when exec
’d.
O_NOFOLLOW (0b0010000)
Do not follow symlinks when opening the file.
O_NONBLOCK (0b0100000)
Make the file not block on read or write operations when possible.
O_CLOFORK (0b1000000)
Will make the file close when fork
’d.
If no O_RDONLY
or O_WRONLY
is passed, the open operation will
result in a file descriptor supporting only stat and navigating operations.
The syscall returns the opened file descriptor or -1
on error, and errno
is set to the following:
ENOENT
: The referenced file does not exist.
EINVAL
: Combination of flags
is not valid.
EMFILE
: Too many files are already owned by the process.
EFAULT
: The passed path is outside the available address space.