Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ setbuf(3S) — SunOS 0.4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fopen(3)

getc(3)

putc(3)

malloc(3)

fclose(3)

puts(3)

printf(3)

fread(3)

SETBUF(3S)  —  System Interface Manual — Standard I/O Library

NAME

setbuf, setbuffer − assign buffering to a stream

SYNOPSIS

#include <stdio.h>

setbuf(stream, buf)
FILE ∗stream;
char ∗buf;

setbuffer(stream, buf, size)
FILE ∗stream;
char ∗buf;
int size;

DESCRIPTION

Setbuf is used after a stream has been opened but before it is read or written.  The character array buf is used instead of an automatically allocated buffer.  If buf is the constant pointer NULL, input/output will be completely unbuffered. 

A manifest constant BUFSIZ tells how big an array is needed:

char buf[BUFSIZ];

Setbuffer is an alternate form of setbuf. The character array buf whose size is determined by the size argument is used instead of an automatically allocated buffer.  If buf is the constant pointer NULL, input/output will be completely unbuffered. 

A buffer is normally obtained from malloc(3) upon the first getc or putc(3) on the file, except that the standard stream stdout is normally buffered if the output refers to a terminal; The standard stream stderr is by default unbuffered, but use of freopen (see fopen(3)) will make it buffered; setbuf, again, will set the state to whatever is desired. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is buffered many characters are saved up and written as a block. Fflush (see fclose(3)) may be used to force the block out early. Other output streams directed to terminals are normally not buffered. If the standard output is line buffered, it is flushed each time data is read from the standard input by read(2).

SEE ALSO

fopen(3), getc(3), putc(3), malloc(3), fclose(3), puts(3), printf(3), fread(3)

BUGS

The standard error stream should be line buffered by default. 

The setbuffer function is not portable to non 4.2 BSD versions of UNIX. 

The standard stream stdout is normally buffered if the output refers to a terminal; The standard stream stderr is by default unbuffered, but use of freopen (see fopen(3)) will make it buffered; setbuf, again, will set the state to whatever is desired. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is buffered many characters are saved up and written as a block. Fflush (see fclose(3)) may be used to force the block out early.

Sun System Release 0.3  —  19 January 1983

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026