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