1.\" $OpenBSD: setbuf.3,v 1.16 2014/11/25 19:08:14 millert Exp $ 2.\" 3.\" Copyright (c) 1980, 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.\" the American National Standards Committee X3, on Information 8.\" 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: November 25 2014 $ 35.Dt SETBUF 3 36.Os 37.Sh NAME 38.Nm setbuf , 39.Nm setbuffer , 40.Nm setlinebuf 41.Nd stream buffering operations 42.Sh SYNOPSIS 43.In stdio.h 44.Ft void 45.Fn setbuf "FILE *stream" "char *buf" 46.Ft void 47.Fn setbuffer "FILE *stream" "char *buf" "size_t size" 48.Ft int 49.Fn setlinebuf "FILE *stream" 50.Sh DESCRIPTION 51.Bf -symbolic 52These interfaces are obsoleted by 53.Xr setvbuf 3 . 54.Ef 55.Pp 56The 57.Fn setbuf , 58.Fn setbuffer , 59and 60.Fn setlinebuf 61functions are used to modify the buffering of a stream. 62These functions are provided for compatibility with legacy code. 63New code should use 64.Xr setvbuf 3 65instead. 66.Pp 67Except for the lack of a return value, the 68.Fn setbuf 69function is exactly equivalent to the call 70.Pp 71.Dl "setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);" 72.Pp 73The 74.Fn setbuffer 75function is the same, except that the size of the buffer is up to the caller, 76rather than being determined by the default 77.Dv BUFSIZ . 78.Pp 79The 80.Fn setlinebuf 81function is exactly equivalent to the call: 82.Pp 83.Dl "setvbuf(stream, NULL, _IOLBF, 0);" 84.Sh RETURN VALUES 85Upon successful completion, the 86.Fn setlinebuf 87function returns 0. 88If the request cannot be honored, a non-zero value is returned, 89possibly setting 90.Va errno 91to indicate the error. 92The stream is not modified in the error case. 93.Sh ERRORS 94The 95.Fn setbuf , 96.Fn setbuffer , 97and 98.Fn setlinebuf 99functions will fail if: 100.Bl -tag -width Er 101.It Bq Er EBADF 102The 103.Fa stream 104specified is not associated with a valid file descriptor. 105.El 106.Sh SEE ALSO 107.Xr fclose 3 , 108.Xr fopen 3 , 109.Xr fread 3 , 110.Xr malloc 3 , 111.Xr printf 3 , 112.Xr puts 3 , 113.Xr setvbuf 3 114.Sh STANDARDS 115The 116.Fn setbuf 117function conforms to 118.St -isoC-99 . 119The 120.Fn setbuffer 121and 122.Fn setlinebuf 123functions are non-standard and should not be used if portability is required. 124.Sh HISTORY 125The 126.Fn setbuf 127function first appeared in 128.At v7 . 129The 130.Fn setbuffer 131function first appeared in 132.Bx 4.1c . 133The 134.Fn setlinebuf 135function first appeared in 136.Bx 4.2 . 137.Sh BUGS 138The 139.Fn setbuf 140function usually uses a suboptimal buffer size and should be avoided. 141