xref: /netbsd/lib/libc/stdio/putc.3 (revision bf9ec67e)
1.\"	$NetBSD: putc.3,v 1.7 2002/02/07 07:00:26 ross 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. It 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
86.Fn putchar
87is identical to
88.Fn putc
89with an output stream of
90.Em stdout .
91.Pp
92The
93.Fn putc_unlocked
94and
95.Fn putchar_unlocked
96functions provide functionality identical to that of
97.Fn putc
98and
99.Fn putchar ,
100respectively, but do not perform implicit locking of the streams they
101operate on.
102In multi-threaded programs they may be used
103.Em only
104within a scope in which the stream
105has been successfully locked by the calling thread using either
106.Xr flockfile 3
107or
108.Xr ftrylockfile 3 ,
109and may later be released using
110.Xr funlockfile 3 .
111.Pp
112The
113.Fn putw
114function
115writes the specified
116.Em int
117to the named output
118.Fa stream .
119.Sh RETURN VALUES
120The functions,
121.Fn fputc ,
122.Fn putc
123and
124.Fn putchar
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 fopen 3 ,
140.Xr getc 3 ,
141.Xr stdio 3
142.Sh STANDARDS
143The functions
144.Fn fputc ,
145.Fn putc ,
146and
147.Fn putchar ,
148conform to
149.St -ansiC .
150The functions
151.Fn putc_unlocked
152and
153.Fn putchar_unlocked
154conform to
155.St -p1003.1-96 .
156A function
157.Fn putw
158function appeared in
159.At v6 .
160.Sh BUGS
161The size and byte order of an
162.Em int
163varies from one machine to another, and
164.Fn putw
165is not recommended for portable applications.
166