Programming and posix - April 2002

April 3, 2002
Solution Symposium
Page 34
hp e3000
programming
and posix
file management - open()/close()
int open (const char *path, int oflag, int modes);
returns -1 for error, else returns file descriptor
ONE of O_RDONLY, O_WRONLY, O_RDWR
O_APPEND - file offset set to EOF prior to writes
O_CREATE - opt. permission modes parm is req’d
O_EXCL - exclusive access
can function as a semaphore by specifying both
O_CREATE and O_EXCL which will return an error if
the file already exists, else will create the file
int close (int fildes);
can also be used on socket descriptors