xref: /openbsd/lib/libc/stdio/putc.3 (revision 404b540a)
1.\"	$OpenBSD: putc.3,v 1.10 2007/05/31 19:19:31 jmc 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. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: May 31 2007 $
35.Dt PUTC 3
36.Os
37.Sh NAME
38.Nm fputc ,
39.Nm putc ,
40.Nm putchar ,
41.Nm putw
42.Nd output a character or word to a stream
43.Sh SYNOPSIS
44.Fd #include <stdio.h>
45.Ft int
46.Fn fputc "int c" "FILE *stream"
47.Ft int
48.Fn putc "int c" "FILE *stream"
49.Ft int
50.Fn putchar "int c"
51.Ft int
52.Fn putw "int w" "FILE *stream"
53.Sh DESCRIPTION
54The
55.Fn fputc
56function writes the character
57.Fa c
58(converted to an
59.Li unsigned char )
60to the output stream pointed to by
61.Fa stream .
62.Pp
63.Fn putc
64acts essentially identically to
65.Fn fputc ,
66but is a macro that expands in-line.
67It may evaluate
68.Fa stream
69more than once, so arguments given to
70.Fn putc
71should not be expressions with potential side effects.
72.Pp
73.Fn putchar
74is identical to
75.Fn putc
76with an output stream of
77.Em stdout .
78.Pp
79The
80.Fn putw
81function writes the specified
82.Li int
83.Fa w
84to the named output
85.Fa stream .
86.Sh RETURN VALUES
87The functions
88.Fn fputc ,
89.Fn putc ,
90and
91.Fn putchar
92return the character written.
93If an error occurs, the value
94.Dv EOF
95is returned and the global variable
96.Va errno
97is set to indicate the error.
98The
99.Fn putw
100function returns 0 on success;
101.Dv EOF
102is returned if a write error occurs,
103or if an attempt is made to write a read-only stream.
104The global variable
105.Va errno
106may be set to indicate the error.
107.Sh ERRORS
108The function
109.Fn putw
110may also fail and set
111.Va errno
112for any of the errors specified for the routines
113.Xr write 2
114or
115.Xr realloc 3 .
116.Sh SEE ALSO
117.Xr ferror 3 ,
118.Xr fopen 3 ,
119.Xr getc 3 ,
120.Xr stdio 3
121.Sh STANDARDS
122The functions
123.Fn fputc ,
124.Fn putc ,
125and
126.Fn putchar ,
127conform to
128.St -ansiC .
129A function
130.Fn putw
131function appeared in
132.At v6 .
133.Sh BUGS
134Since the size and byte order of an
135.Li int
136may vary from one machine to another,
137.Fn putw
138is not recommended for portable applications.
139