1FLOPEN(3bsd)                         LOCAL                        FLOPEN(3bsd)
2

NAME

4     flopen, flopenat — 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     (See libbsd(7) for include usage.)
13
14     int
15     flopen(const char *path, int flags);
16
17     int
18     flopen(const char *path, int flags, mode_t mode);
19
20     int
21     flopenat(int fd, const char *path, int flags);
22
23     int
24     flopenat(int fd, const char *path, int flags, mode_t mode);
25

DESCRIPTION

27     The flopen() function opens or creates a file and acquires an exclusive
28     lock on it.  It is essentially equivalent with calling open() with the
29     same parameters followed by flock() with an operation argument of
30     LOCK_EX, except that flopen() will attempt to detect and handle races
31     that may occur between opening / creating the file and locking it.  Thus,
32     it is well suited for opening lock files, PID files, spool files, mail‐
33     boxes and other kinds of files which are used for synchronization between
34     processes.
35
36     If flags includes O_NONBLOCK and the file is already locked, flopen()
37     will fail and set errno to EWOULDBLOCK.
38
39     As with open(), the additional mode argument is required if flags
40     includes O_CREAT.
41
42     The flopenat() function is equivalent to the flopen() function except in
43     the case where the path specifies a relative path.  In this case the file
44     to be opened is determined relative to the directory associated with the
45     file descriptor fd instead of the current working directory.  If
46     flopenat() is passed the special value AT_FDCWD in the fd parameter, the
47     current working directory is used and the behavior is identical to a call
48     to flopen().
49

RETURN VALUES

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

SEE ALSO

55     errno(2), flock(2), open(2)
56

AUTHORS

58     The flopen function and this manual page were written by Dag-Erling
59     Smørgrav <des@FreeBSD.org>.
60
61BSD                              July 28, 2017                             BSD
Impressum