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