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