HomeManualTopicsTypesSymbols

std::open

opens a file

Parameters

pathname
the path of the file to open
flags
whether to open the file for reading, writing or appending
mode (optional)
the mode of the file

Result

fd: a file descriptor

Description

On success a valid file handle is returned, on failure an appropriate error-object is returned.

Possible flag combinations:

r: Open a file for reading only.

r+: Open a file for reading and writing.

w: Create a new or truncate an existing file and open it for writing only.

w+: Create a new or truncate an existing file and open it for reading and writing.

a: Create a new or open an existing file. The current file position is initially at the end of the file. The file is opened for writing only.

a+: Create a new or open an existing file. The current file position is initially at the end of the file. The file is opened for reading and writing.

The optional mode parameter is a string of the form "rwxrwxrwx". The default value is "rw-r--r--".

This function needs I/O-access rights.

Example

open! $fd "test.txt" "w+" write! $bytes_written fd "Hello, World!" on bytes_written.is_an_error: Error! "Failed to write to file!" close! fd

Topic

POSIX

See also

std::close closes the specified file without returning success status
std::read a low level read function
std::write a low level write function
std::fsync flushes all buffers associated with the file descriptor