source: trunk/minix/man/man3/setbuf.3@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.7 KB
RevLine 
[9]1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)setbuf.3s 6.2 (Berkeley) 5/12/86
6.\"
7.TH SETBUF 3 "May 12, 1986"
8.UC 4
9.SH NAME
10setbuf, setvbuf \- assign buffering to a stream
11.SH SYNOPSIS
12.nf
13.ft B
14#include <stdio.h>
15
16int setbuf(FILE *\fIstream\fP, char *\fIbuf\fP)
17int setvbuf(FILE *\fIstream\fP, char *\fIbuf\fP, int \fItype\fP, size_t \fIsize\fP)
18.SH DESCRIPTION
19The three types of buffering available are unbuffered, block buffered,
20and line buffered.
21When an output stream is unbuffered, information appears on the
22destination file or terminal as soon as written;
23when it is block buffered many characters are saved up and written as a block;
24when it is line buffered characters are saved up until a newline is
25encountered or input is read from stdin.
26.B Fflush
27(see
28.BR fclose (3))
29may be used to force the block out early.
30Normally all files are block buffered.
31A buffer is obtained from
32.BR malloc (3)
33upon the first
34.B getc
35or
36.BR putc (3)
37on the file.
38If the standard stream
39.B stdout
40refers to a terminal it is line buffered.
41The standard stream
42.B stderr
43is always unbuffered.
44.PP
45.B Setbuf
46is used after a stream has been opened but before it is read or written.
47The character array
48.I buf
49is used instead of an automatically allocated buffer. If
50.I buf
51is the constant pointer
52.SM
53.BR NULL ,
54input/output will be completely unbuffered.
55A manifest constant
56.SM
57.B BUFSIZ
58tells how big an array is needed:
59.IP
60.B char
61buf[BUFSIZ];
62.PP
63.BR Setvbuf ,
64an alternate form of
65.BR setbuf ,
66is used after a stream has been opened but before it is read or written.
67It has three uses, depending on the value of the
68.IR type
69argument:
70.TP 5
71.B "setvbuf(\fIstream\fP, \fIbuf\fP, _IOFBF, \fIsize\fP)"
72Causes input/output to be fully buffered using the character array
73.I buf
74whose size is determined by the
75.I size
76argument.
77If
78.I buf
79is the constant pointer
80.SM
81.BR NULL ,
82then an automatically allocated buffer will be used.
83.TP 5
84.B "setvbuf(\fIstream\fP, \fIbuf\fP, _IOLBF, \fIsize\fP)"
85Like above, except that output will be line buffered, i.e. the buffer will
86be flushed when a newline is written, the buffer is full, or input is
87requested.
88.TP 5
89.B "setvbuf(\fIstream\fP, \fIbuf\fP, _IONBF, \fIsize\fP)"
90Causes input/output to be completely unbuffered.
91.I Buf
92and
93.I size
94are ignored.
95.PP
96A file can be changed between unbuffered, line buffered, or block buffered
97by using
98.B freopen
99(see
100.BR fopen (3))
101followed by the appropriate
102.B setvbuf
103call.
104.SH "SEE ALSO"
105.BR fopen (3),
106.BR getc (3),
107.BR putc (3),
108.BR malloc (3),
109.BR fclose (3),
110.BR puts (3),
111.BR printf (3),
112.BR fread (3).
Note: See TracBrowser for help on using the repository browser.