9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / flockfile.3c
blob66c56654ebd03a8494a3973dcea575cf61a39550
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 2003 Sun Microsystems, Inc.  All Rights Reserved.
45 .\"
46 .TH FLOCKFILE 3C "Sep 10, 2003"
47 .SH NAME
48 flockfile, funlockfile, ftrylockfile \- acquire and release stream lock
49 .SH SYNOPSIS
50 .LP
51 .nf
52 #include <stdio.h>
54 \fBvoid\fR \fBflockfile\fR(\fBFILE *\fR\fIstream\fR);
55 .fi
57 .LP
58 .nf
59 \fBvoid\fR \fBfunlockfile\fR(\fBFILE *\fR\fIstream\fR);
60 .fi
62 .LP
63 .nf
64 \fBint\fR \fBftrylockfile\fR(\fBFILE *\fR\fIstream\fR);
65 .fi
67 .SH DESCRIPTION
68 .sp
69 .LP
70 The \fBflockfile()\fR function acquires an internal lock of a stream
71 \fIstream\fR. If the lock is already acquired by another thread, the thread
72 calling \fBflockfile()\fR is suspended until it can acquire the lock.  In the
73 case that the stream lock is available, \fBflockfile()\fR not only acquires the
74 lock, but keeps track of the number of times it is being called by the current
75 thread.  This implies that the stream lock can be acquired more than once by
76 the same thread.
77 .sp
78 .LP
79 The \fBfunlockfile()\fR function releases the lock being held by the current
80 thread.  In the case of recursive locking, this function must be called the
81 same number of times \fBflockfile()\fR was called.  After the number of
82 \fBfunlockfile()\fR calls is equal to the number of \fBflockfile()\fR calls,
83 the stream lock is available for other threads to acquire.
84 .sp
85 .LP
86 The \fBftrylockfile()\fR function acquires an internal lock of a stream
87 \fIstream\fR, only if that object is available.  In essence
88 \fBftrylockfile()\fR is a non-blocking version of \fBflockfile()\fR.
89 .SH RETURN VALUES
90 .sp
91 .LP
92 The \fBftrylockfile()\fR function returns \fB0\fR on success and non-zero to
93 indicate a lock cannot be acquired.
94 .SH EXAMPLES
95 .LP
96 \fBExample 1 \fRA sample program of \fBflockfile()\fR.
97 .sp
98 .LP
99 The following example prints everything out together, blocking other threads
100 that might want to write to the same file between calls to \fBfprintf\fR(3C):
103 .in +2
105 FILE iop;
106 flockfile(iop);
107 fprintf(iop, "hello ");
108 fprintf(iop, "world);
109 fputc(iop, 'a');
110 funlockfile(iop);
112 .in -2
116 An unlocked interface is available in case performance is an issue.  For
117 example:
120 .in +2
122 flockfile(iop);
123 while (!feof(iop)) {
124         *c++ = getc_unlocked(iop);
126 funlockfile(iop);
128 .in -2
130 .SH ATTRIBUTES
133 See \fBattributes\fR(5) for descriptions of the following attributes:
138 box;
139 c | c
140 l | l .
141 ATTRIBUTE TYPE  ATTRIBUTE VALUE
143 Interface Stability     Standard
145 MT-Level        MT-Safe
148 .SH SEE ALSO
151 \fBIntro\fR(3), \fB__fsetlocking\fR(3C), \fBferror\fR(3C), \fBfprintf\fR(3C),
152 \fBgetc\fR(3C), \fBputc\fR(3C), \fBstdio\fR(3C), \fBungetc\fR(3C),
153 \fBattributes\fR(5), \fBstandards\fR(5)
154 .SH NOTES
157 The interfaces on this page  are as specified in IEEE Std 1003.1:2001.  See
158 \fBstandards\fR(5).