]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libc/stdio/putc.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libc / stdio / putc.3
1 .\" Copyright (c) 1990, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)putc.3      8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD$
34 .\"
35 .Dd January 10, 2003
36 .Dt PUTC 3
37 .Os
38 .Sh NAME
39 .Nm fputc ,
40 .Nm putc ,
41 .Nm putc_unlocked ,
42 .Nm putchar ,
43 .Nm putchar_unlocked ,
44 .Nm putw
45 .Nd output a character or word to a stream
46 .Sh LIBRARY
47 .Lb libc
48 .Sh SYNOPSIS
49 .In stdio.h
50 .Ft int
51 .Fn fputc "int c" "FILE *stream"
52 .Ft int
53 .Fn putc "int c" "FILE *stream"
54 .Ft int
55 .Fn putc_unlocked "int c" "FILE *stream"
56 .Ft int
57 .Fn putchar "int c"
58 .Ft int
59 .Fn putchar_unlocked "int c"
60 .Ft int
61 .Fn putw "int w" "FILE *stream"
62 .Sh DESCRIPTION
63 The
64 .Fn fputc
65 function
66 writes the character
67 .Fa c
68 (converted to an ``unsigned char'')
69 to the output stream pointed to by
70 .Fa stream .
71 .Pp
72 The
73 .Fn putc
74 macro acts essentially identically to
75 .Fn fputc ,
76 but is a macro that expands in-line.
77 It may evaluate
78 .Fa stream
79 more than once, so arguments given to
80 .Fn putc
81 should not be expressions with potential side effects.
82 .Pp
83 The
84 .Fn putchar
85 function
86 is identical to
87 .Fn putc
88 with an output stream of
89 .Dv stdout .
90 .Pp
91 The
92 .Fn putw
93 function
94 writes the specified
95 .Vt int
96 to the named output
97 .Fa stream .
98 .Pp
99 The
100 .Fn putc_unlocked
101 and
102 .Fn putchar_unlocked
103 functions are equivalent to
104 .Fn putc
105 and
106 .Fn putchar
107 respectively,
108 except that the caller is responsible for locking the stream
109 with
110 .Xr flockfile 3
111 before calling them.
112 These functions may be used to avoid the overhead of locking the stream
113 for each character, and to avoid output being interspersed from multiple
114 threads writing to the same stream.
115 .Sh RETURN VALUES
116 The functions,
117 .Fn fputc ,
118 .Fn putc ,
119 .Fn putchar ,
120 .Fn putc_unlocked
121 and
122 .Fn putchar_unlocked
123 return the character written.
124 If an error occurs, the value
125 .Dv EOF
126 is returned.
127 The
128 .Fn putw
129 function
130 returns 0 on success;
131 .Dv EOF
132 is returned if
133 a write error occurs,
134 or if an attempt is made to write a read-only stream.
135 .Sh SEE ALSO
136 .Xr ferror 3 ,
137 .Xr flockfile 3 ,
138 .Xr fopen 3 ,
139 .Xr getc 3 ,
140 .Xr putwc 3 ,
141 .Xr stdio 3
142 .Sh STANDARDS
143 The functions
144 .Fn fputc ,
145 .Fn putc ,
146 and
147 .Fn putchar ,
148 conform to
149 .St -isoC .
150 The
151 .Fn putc_unlocked
152 and
153 .Fn putchar_unlocked
154 functions conform to
155 .St -p1003.1-2001 .
156 A function
157 .Fn putw
158 function appeared in
159 .At v6 .
160 .Sh BUGS
161 The size and byte order of an
162 .Vt int
163 varies from one machine to another, and
164 .Fn putw
165 is not recommended for portable applications.