nrelease - fix/improve livecd
[dragonfly.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 .\" 3. 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: src/lib/libc/stdio/putc.3,v 1.16 2007/01/09 00:28:07 imp Exp $
34 .\"
35 .Dd November 22, 2020
36 .Dt PUTC 3
37 .Os
38 .Sh NAME
39 .Nm fputc ,
40 .Nm fputc_unlocked ,
41 .Nm putc ,
42 .Nm putc_unlocked ,
43 .Nm putchar ,
44 .Nm putchar_unlocked ,
45 .Nm putw
46 .Nd output a character or word to a stream
47 .Sh LIBRARY
48 .Lb libc
49 .Sh SYNOPSIS
50 .In stdio.h
51 .Ft int
52 .Fn fputc "int c" "FILE *stream"
53 .Ft int
54 .Fn fputc_unlocked "int c" "FILE *stream"
55 .Ft int
56 .Fn putc "int c" "FILE *stream"
57 .Ft int
58 .Fn putc_unlocked "int c" "FILE *stream"
59 .Ft int
60 .Fn putchar "int c"
61 .Ft int
62 .Fn putchar_unlocked "int c"
63 .Ft int
64 .Fn putw "int w" "FILE *stream"
65 .Sh DESCRIPTION
66 The
67 .Fn fputc
68 function
69 writes the character
70 .Fa c
71 (converted to an ``unsigned char'')
72 to the output stream pointed to by
73 .Fa stream .
74 .Pp
75 The
76 .Fn putc
77 macro acts essentially identically to
78 .Fn fputc ,
79 but is a macro that expands in-line.
80 It may evaluate
81 .Fa stream
82 more than once, so arguments given to
83 .Fn putc
84 should not be expressions with potential side effects.
85 .Pp
86 The
87 .Fn putchar
88 function
89 is identical to
90 .Fn putc
91 with an output stream of
92 .Dv stdout .
93 .Pp
94 The
95 .Fn putw
96 function
97 writes the specified
98 .Vt int
99 to the named output
100 .Fa stream .
101 .Pp
102 The
103 .Fn fputc_unlocked ,
104 .Fn putc_unlocked ,
105 and
106 .Fn putchar_unlocked
107 functions are equivalent to
108 .Fn fputc ,
109 .Fn putc ,
110 and
111 .Fn putchar
112 respectively,
113 except that the caller is responsible for locking the stream
114 with
115 .Xr flockfile 3
116 before calling them.
117 These functions may be used to avoid the overhead of locking the stream
118 for each character, and to avoid output being interspersed from multiple
119 threads writing to the same stream.
120 .Sh RETURN VALUES
121 The functions,
122 .Fn fputc ,
123 .Fn putc ,
124 .Fn putchar ,
125 .Fn putc_unlocked
126 and
127 .Fn putchar_unlocked
128 return the character written.
129 If an error occurs, the value
130 .Dv EOF
131 is returned.
132 The
133 .Fn putw
134 function
135 returns 0 on success;
136 .Dv EOF
137 is returned if
138 a write error occurs,
139 or if an attempt is made to write a read-only stream.
140 .Sh SEE ALSO
141 .Xr ferror 3 ,
142 .Xr flockfile 3 ,
143 .Xr fopen 3 ,
144 .Xr getc 3 ,
145 .Xr putwc 3 ,
146 .Xr stdio 3
147 .Sh STANDARDS
148 The functions
149 .Fn fputc ,
150 .Fn putc ,
151 and
152 .Fn putchar ,
153 conform to
154 .St -isoC .
155 The
156 .Fn putc_unlocked
157 and
158 .Fn putchar_unlocked
159 functions conform to
160 .St -p1003.1-2001 .
161 A function
162 .Fn putw
163 function appeared in
164 .At v6 .
165 .Sh BUGS
166 The size and byte order of an
167 .Vt int
168 varies from one machine to another, and
169 .Fn putw
170 is not recommended for portable applications.