1.\"-
2.\" Copyright (c) 2007 Dag-Erling Co�dan Sm�rgrav
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
--- 9 unchanged lines hidden (view full) ---
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD: head/lib/libutil/flopen.3 171705 2007-08-03 06:32:45Z des $
27.\"
28.Dd July 30, 2007
29.Dt FLOPEN 3
30.Os
31.Sh NAME
32.Nm flopen
33.Nd "Reliably open and lock a file"
34.Sh LIBRARY
35.Lb libutil
36.Sh SYNOPSIS
--- 4 unchanged lines hidden (view full) ---
41.Ft int
42.Fn flopen "const char *path" "int flags" "mode_t mode"
43.Sh DESCRIPTION
44The
45.Fn flopen
46function opens or creates a file and acquires an exclusive lock on it.
47It is essentially equivalent with calling
48.Fn open
49with the same parameters and then acquiring a lock on the entire file
50using
51.Fn fcntl "F_SETLK" ,
52except that
53.Fn flopen
54will attempt to detect and handle races that may occur between opening
55/ creating the file and locking it.
56Thus, it is well suited for opening lock files, PID files, spool
57files, mailboxes and other kinds of files which are used for
58synchronization between processes.
59.Pp
--- 18 unchanged lines hidden (view full) ---
78.Dv O_CREAT .
79.Sh RETURN VALUES
80If successful,
81.Fn flopen
82returns a valid file descriptor.
83Otherwise, it returns -1, and sets
84.Va errno
85as described in
86.Xr fcntl 2
87and
88.Xr open 2 .
89.Sh SEE ALSO
90.Xr errno 2 ,
91.Xr fcntl 2 ,
92.Xr open 2
93.Sh AUTHORS
94.An -nosplit
95The
96.Nm
97function and this manual page were written by
98.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
2.\" Copyright (c) 2007 Dag-Erling Co�dan Sm�rgrav
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
--- 9 unchanged lines hidden (view full) ---
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD: head/lib/libutil/flopen.3 171705 2007-08-03 06:32:45Z des $
27.\"
28.Dd July 30, 2007
29.Dt FLOPEN 3
30.Os
31.Sh NAME
32.Nm flopen
33.Nd "Reliably open and lock a file"
34.Sh LIBRARY
35.Lb libutil
36.Sh SYNOPSIS
--- 4 unchanged lines hidden (view full) ---
41.Ft int
42.Fn flopen "const char *path" "int flags" "mode_t mode"
43.Sh DESCRIPTION
44The
45.Fn flopen
46function opens or creates a file and acquires an exclusive lock on it.
47It is essentially equivalent with calling
48.Fn open
49with the same parameters and then acquiring a lock on the entire file
50using
51.Fn fcntl "F_SETLK" ,
52except that
53.Fn flopen
54will attempt to detect and handle races that may occur between opening
55/ creating the file and locking it.
56Thus, it is well suited for opening lock files, PID files, spool
57files, mailboxes and other kinds of files which are used for
58synchronization between processes.
59.Pp
--- 18 unchanged lines hidden (view full) ---
78.Dv O_CREAT .
79.Sh RETURN VALUES
80If successful,
81.Fn flopen
82returns a valid file descriptor.
83Otherwise, it returns -1, and sets
84.Va errno
85as described in
86.Xr fcntl 2
87and
88.Xr open 2 .
89.Sh SEE ALSO
90.Xr errno 2 ,
91.Xr fcntl 2 ,
92.Xr open 2
93.Sh AUTHORS
94.An -nosplit
95The
96.Nm
97function and this manual page were written by
98.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .