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_WRITEONLYO_CREAT
create the file is it don’t exist the optional argumentmodeis 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 theexecvesyscall 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 useopendirinstead of the raw syscallreturn code
open return the id the the new file descriptor or -1 and set
errnoif an error happendEFAULT
pathpoint to outside of the addrassable spaceEEXIST
O_CREATandO_EXCLwere set but the file aready existENOENT
pathdon’t existEISDIR
pathis a directory butO_DIRECTORYwas noe specifiedENOTDIR
O_DIRECTORYwas specified butpathis not a directoryEPERM
permission issue