flopen (3) - Linux Man Pages
flopen: reliably open and lock a file
flopen - reliably open and lock a file
SYNOPSISIn sys/fcntl.h In bsd/libutil.h Ft int Fn flopen const char *path int flags Ft int Fn flopen const char *path int flags mode_t mode
DESCRIPTIONThe Fn flopen function opens or creates a file and acquires an exclusive lock on it. It is essentially equivalent with calling Fn open with the same parameters followed by Fn flock with an operation argument of LOCK_EX except that Fn flopen will attempt to detect and handle races that may occur between opening / creating the file and locking it. Thus, it is well suited for opening lock files, PID files, spool files, mailboxes and other kinds of files which are used for synchronization between processes.
If flags includes O_NONBLOCK and the file is already locked, Fn flopen will fail and set errno to EWOULDBLOCK
As with Fn open , the additional mode argument is required if flags includes O_CREAT
RETURN VALUESIf successful, Fn flopen returns a valid file descriptor. Otherwise, it returns -1, and sets errno as described in flock(2) and open(2).
AUTHORSAn -nosplit The function and this manual page were written by An Dag-Erling Smørgrav Aq des [at] FreeBSD.org .