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