1.\" $NetBSD: putc.3,v 1.15 2024/12/12 06:18:24 rillig 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.\" @(#)putc.3 8.1 (Berkeley) 6/4/93 35.\" 36.Dd September 2, 2019 37.Dt PUTC 3 38.Os 39.Sh NAME 40.Nm fputc , 41.Nm putc , 42.Nm putchar , 43.Nm putc_unlocked , 44.Nm putchar_unlocked , 45.Nm putw 46.Nd output a character or word to a stream 47.Sh LIBRARY 48.Lb libc 49.Sh SYNOPSIS 50.In stdio.h 51.Ft int 52.Fn fputc "int c" "FILE *stream" 53.Ft int 54.Fn putc "int c" "FILE *stream" 55.Ft int 56.Fn putchar "int c" 57.Ft int 58.Fn putc_unlocked "int c" "FILE *stream" 59.Ft int 60.Fn putchar_unlocked "int c" 61.Ft int 62.Fn putw "int w" "FILE *stream" 63.Sh DESCRIPTION 64The 65.Fn fputc 66function 67writes the character 68.Fa c 69(converted to an 70.Dq unsigned char ) 71to the output stream pointed to by 72.Fa stream . 73.Pp 74.Fn putc 75acts essentially identically to 76.Fn fputc , 77but is a macro that expands in-line. 78It may evaluate 79.Fa stream 80more than once, so arguments given to 81.Fn putc 82should not be expressions with potential side effects. 83.Pp 84.Fn putchar 85is identical to 86.Fn putc 87with an output stream of 88.Em stdout . 89.Pp 90The 91.Fn putc_unlocked 92and 93.Fn putchar_unlocked 94functions provide functionality identical to that of 95.Fn putc 96and 97.Fn putchar , 98respectively, but do not perform implicit locking of the streams they 99operate on. 100In multi-threaded programs they may be used 101.Em only 102within a scope in which the stream 103has been successfully locked by the calling thread using either 104.Xr flockfile 3 105or 106.Xr ftrylockfile 3 , 107and may later be released using 108.Xr funlockfile 3 . 109.Pp 110The 111.Fn putw 112function 113writes the specified 114.Em int 115to the named output 116.Fa stream , 117in a binary format. 118.Sh RETURN VALUES 119The functions 120.Fn fputc , 121.Fn putc 122and 123.Fn putchar 124return the character written. 125If an error occurs, the value 126.Dv EOF 127is returned. 128The 129.Fn putw 130function 131returns 0 on success; 132.Dv EOF 133is returned if 134a write error occurs, 135or if an attempt is made to write a read-only stream. 136.Sh SEE ALSO 137.Xr ferror 3 , 138.Xr flockfile 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 . 156.Sh HISTORY 157The 158.Fn putc 159and 160.Fn putw 161functions first appeared in 162.At v1 . 163The 164.Fn putchar 165function first appeared in 166.At v4 . 167The function 168.Fn fputc 169appeared in 170.At v7 . 171.Sh BUGS 172The size and byte order of an 173.Em int 174varies from one machine to another, and 175.Fn putw 176is not recommended for portable applications. 177