Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ setbuf(3S) — GL1 W2.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fopen(3S)

getc(3S)

malloc(3C)

putc(3S)

SETBUF(3S)  —  Silicon Graphics

NAME

setbuf − assign buffering to a stream

SYNOPSIS

#include <stdio.h>

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

DESCRIPTION

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

A constant BUFSIZ, defined in the <stdio.h> header file, tells how big an array is needed:

char buf[BUFSIZ];

A buffer is normally obtained from malloc(3C) at the time of the first getc or putc(3S) on the file, except that the standard error stream stderr is normally not buffered. 

Output streams directed to terminals are always line-buffered unless they are unbuffered. 

SEE ALSO

fopen(3S), getc(3S), malloc(3C), putc(3S). 

NOTE

A common source of error is allocating buffer space as an “automatic” variable in a code block, and then failing to close the stream in the same block. 

Version 2.3  —  July 04, 1985

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