9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / setbuffer.3c
blob78a42edc2c7543ad465c4f8373122425aa2e3fb9
1 '\" te
2 .\"  Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SETBUFFER 3C "May 13, 1997"
7 .SH NAME
8 setbuffer, setlinebuf \- assign buffering to a stream
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <stdio.h>
14 \fBvoid\fR \fBsetbuffer\fR(\fBFILE *\fR\fIiop\fR, \fBchar *\fR\fIabuf\fR, \fBsize_t\fR \fIasize\fR);
15 .fi
17 .LP
18 .nf
19 \fBint\fR \fBsetlinebuf\fR(\fBFILE *\fR\fIiop\fR);
20 .fi
22 .SH DESCRIPTION
23 .sp
24 .LP
25 The \fBsetbuffer()\fR and \fBsetlinebuf()\fR functions assign buffering to a
26 stream. The three types of buffering available are unbuffered, block buffered,
27 and line buffered. When an output stream is unbuffered, information appears on
28 the destination file or terminal as soon as written; when it is block buffered,
29 many characters are saved and written as a block; when it is line buffered,
30 characters are saved until either a \fBNEWLINE\fR is encountered or input is
31 read from \fBstdin\fR. The \fBfflush\fR(3C) function may be used to force the
32 block out early. Normally all files are block buffered. A buffer is obtained
33 from \fBmalloc\fR(3C) upon the first \fBgetc\fR(3C) or \fBputc\fR(3C) performed
34 on the file. If the standard stream \fBstdout\fR refers to a terminal, it is
35 line buffered. The standard stream \fBstderr\fR is unbuffered by default.
36 .sp
37 .LP
38 The \fBsetbuffer()\fR function can be used after a stream \fIiop\fR has been
39 opened but before it is read or written. It uses the character array \fIabuf\fR
40 whose size is determined by the \fIasize\fR argument instead of an
41 automatically allocated buffer.  If \fIabuf\fR is the null pointer,
42 input/output will be completely unbuffered. A manifest constant \fBBUFSIZ\fR,
43 defined in the \fB<stdio.h>\fR header, tells how large an array is needed:
44 .sp
45 .LP
46 char buf[BUFSIZ];
47 .sp
48 .LP
49 The \fBsetlinebuf()\fR function is used to change the buffering on a stream
50 from block buffered or unbuffered to line buffered. Unlike \fBsetbuffer()\fR,
51 it can be used at any time that the stream \fIiop\fR is active.
52 .sp
53 .LP
54 A stream can be changed from unbuffered or line buffered to block buffered by
55 using \fBfreopen\fR(3C). A stream can be changed from block buffered or line
56 buffered to unbuffered by using \fBfreopen\fR(3C) followed by \fBsetbuf\fR(3C)
57 with a buffer argument of \fINULL\fR.
58 .SH RETURN VALUES
59 .sp
60 .LP
61 The \fBsetlinebuf()\fR function returns no useful value.
62 .SH SEE ALSO
63 .sp
64 .LP
65 \fBmalloc\fR(3C), \fBfclose\fR(3C), \fBfopen\fR(3C), \fBfread\fR(3C),
66 \fBgetc\fR(3C), \fBprintf\fR(3C), \fBputc\fR(3C), \fBputs\fR(3C),
67 \fBsetbuf\fR(3C), \fBsetvbuf\fR(3C)
68 .SH NOTES
69 .sp
70 .LP
71 A common source of error is allocating buffer space as an "automatic" variable
72 in a code block, and then failing to close the stream in the same block.