The flags argument should consist of one of
It may also have any of the following flags OR'd in:
O_RDONLY Open for reading only. O_WRONLY Open for writing only. O_RDWR Open for reading and writing.
O_EXCL is only meaningful if O_CREAT is also used.
O_CREAT Create the file if it doesn't exist. O_EXCL Fail if the file already exists. O_TRUNC Truncate the file to length 0 upon open. O_APPEND Open the file in append mode.
O_APPEND causes all writes to the file to occur at the end of file, no matter what gets written to the file by whoever else. (This functionality may be optional; consult your course's assignments.)
open returns a file handle suitable for passing to read, write, close, etc. This file handle must be greater than or equal to zero. Note that file handles 0 (STDIN_FILENO), 1 (STDOUT_FILENO), and 2 (STDERR_FILENO) are used in special ways and are typically assumed by user-level code to always be open.
ENODEV The device prefix of filename did not exist. ENOTDIR A non-final component of filename was not a directory. ENOENT A non-final component of filename did not exist. ENOENT The named file does not exist, and O_CREAT was not specified. EEXIST The named file exists, and O_EXCL was specified. EISDIR The named object is a directory, and it was to be opened for writing. EMFILE The process's file table was full, or a process-specific limit on open files was reached. ENFILE The system file table is full, if such a thing exists, or a system-wide limit on open files was reached. ENXIO The named object is a block device with no mounted filesystem. ENOSPC The file was to be created, and the filesystem involved is full. EINVAL flags contained invalid values. EIO A hard I/O error occurred. EFAULT filename was an invalid pointer.