]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/flockfile.3
Libc-825.40.1.tar.gz
[apple/libc.git] / stdio / FreeBSD / flockfile.3
CommitLineData
9385eb3d
A
1.\" Copyright (c) 2003 Tim J. Robbins
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD: src/lib/libc/stdio/flockfile.3,v 1.3 2003/01/13 01:29:14 tjr Exp $
26.\"
27.Dd January 10, 2003
28.Dt FLOCKFILE 3
29.Os
30.Sh NAME
31.Nm flockfile ,
32.Nm ftrylockfile ,
33.Nm funlockfile
34.Nd "stdio locking functions"
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In stdio.h
39.Ft void
ad3c9f2a 40.Fn flockfile "FILE *file"
9385eb3d 41.Ft int
ad3c9f2a 42.Fn ftrylockfile "FILE *file"
9385eb3d 43.Ft void
ad3c9f2a 44.Fn funlockfile "FILE *file"
9385eb3d 45.Sh DESCRIPTION
ad3c9f2a
A
46These functions provide explicit application-level locking
47of stdio FILE objects.
9385eb3d
A
48They can be used to avoid output from multiple threads being interspersed,
49input being dispersed among multiple readers, and to avoid the overhead
ad3c9f2a 50of locking the object for each operation.
9385eb3d
A
51.Pp
52The
53.Fn flockfile
ad3c9f2a
A
54function acquires an exclusive lock on the specified object.
55If another thread has already locked the object,
9385eb3d
A
56.Fn flockfile
57will block until the lock is released.
58.Pp
59The
60.Fn ftrylockfile
61function is a non-blocking version of
62.Fn flockfile ;
63if the lock cannot be acquired immediately,
64.Fn ftrylockfile
65returns non-zero instead of blocking.
66.Pp
67The
68.Fn funlockfile
ad3c9f2a 69function releases the lock on an object acquired by an earlier call to
9385eb3d
A
70.Fn flockfile
71or
72.Fn ftrylockfile .
73.Pp
74These functions behave as if there is a lock count associated
ad3c9f2a 75with each object.
9385eb3d
A
76Each time
77.Fn flockfile
ad3c9f2a 78is called on the object, the count is incremented,
9385eb3d
A
79and each time
80.Fn funlockfile
ad3c9f2a 81is called on the object, the count is decremented.
9385eb3d
A
82The lock is only actually released when the count reaches zero.
83.Sh RETURN VALUES
84The
85.Fn flockfile
86and
87.Fn funlockfile
88functions return no value.
89.Pp
90The
91.Fn ftrylockfile
92function
ad3c9f2a 93returns zero if the object was successfully locked,
9385eb3d
A
94non-zero otherwise.
95.Sh SEE ALSO
96.Xr getc_unlocked 3 ,
97.Xr putc_unlocked 3
98.Sh STANDARDS
99The
100.Fn flockfile ,
ad3c9f2a 101.Fn ftrylockfile ,
9385eb3d
A
102and
103.Fn funlockfile
104functions conform to
105.St -p1003.1-2001 .