1FLOPEN(3)                BSD Library Functions Manual                FLOPEN(3)
2

NAME

4     flopen — Reliably open and lock a file
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <sys/fcntl.h>
11     #include <libutil.h>
12
13     int
14     flopen(const char *path, int flags);
15
16     int
17     flopen(const char *path, int flags, mode_t mode);
18

DESCRIPTION

20     The flopen() function opens or creates a file and acquires an exclusive
21     lock on it.  It is essentially equivalent with calling open() with the
22     same parameters followed by flock() with an operation argument of
23     LOCK_EX, except that flopen() will attempt to detect and handle races
24     that may occur between opening / creating the file and locking it.  Thus,
25     it is well suited for opening lock files, PID files, spool files, mail‐
26     boxes and other kinds of files which are used for synchronization between
27     processes.
28
29     If flags includes O_NONBLOCK and the file is already locked, flopen()
30     will fail and set errno to EWOULDBLOCK.
31
32     As with open(), the additional mode argument is required if flags
33     includes O_CREAT.
34

RETURN VALUES

36     If successful, flopen() returns a valid file descriptor.  Otherwise, it
37     returns -1, and sets errno as described in flock(2) and open(2).
38

SEE ALSO

40     errno(2), flock(2), open(2)
41

AUTHORS

43     The flopen function and this manual page were written by Dag-Erling
44     Smørgrav <des@FreeBSD.org>.
45
46BSD                              June 6, 2009                              BSD
Impressum