flopen (3)
Leading comments
- Copyright (c) 2007 Dag-Erling Coïdan Smørgrav All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the ...
NAME
flopen - reliably open and lock a fileLIBRARY
Lb libbsdSYNOPSIS
In sys/fcntl.h In libutil.h (See libbsd(7) for include usage.) Ft int Fn flopen const char *path int flags Ft int Fn flopen const char *path int flags mode_t modeDESCRIPTION
The 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