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