open
int open(const char *path,int flags,... /*mode_t mode*/);
use
open
open a file descriptor to the specified pathname
the flags argument allow to open for specific operation and set flags on the file decsriptor
avalibles flags
O_READONLY
open in readonlyO_WRITEONLY
O_CREAT
create the file is it don’t exist the optional argumentmode
is used with this flagsO_EXCL
when used withO_CREAT
, make sure a file is created trigger an error if it can’tO_CLOEXEC
close the file descriptor when theexecve
syscall is callO_APPEND
set the file desciptor in append mode , before each write , the kernel seek to the end of the fileO_DIRECTORY
open a directory
if you want to open a directory you might want to useopendir
instead of the raw syscallreturn code
open return the id the the new file descriptor or -1 and set
errno
if an error happendEFAULT
path
point to outside of the addrassable spaceEEXIST
O_CREAT
andO_EXCL
were set but the file aready existENOENT
path
don’t existEISDIR
path
is a directory butO_DIRECTORY
was noe specifiedENOTDIR
O_DIRECTORY
was specified butpath
is not a directoryEPERM
permission issue