sseettvvbbuuff() -- STDIO Function (libc)

Set alternative file-stream buffer
#iinncclluuddee <ssttddiioo.hh>
iinntt sseettvvbbuuff(_f_p, _b_u_f_f_e_r, _m_o_d_e, _s_i_z_e)
FFIILLEE *_f_p; cchhaarr *_b_u_f_f_e_r; iinntt _m_o_d_e; ssiizzee_tt _s_i_z_e;

When the functions ffooppeenn()  and ffrreeooppeenn() open a stream, they automatically
establish a buffer  for it.  The buffer is BBUUFFSSIIZZ  bytes long.  BBUUFFSSIIZZ is a
manifest constant that is defined in the header ssttddiioo.hh.

The function sseettvvbbuuff() alters the buffer used with the stream pointed to by
_f_p from its default buffer to _b_u_f_f_e_r. Unlike the related function sseettbbuuff(),
it also  allows you set the size  of the new buffer as well  as the form of
buffering.

_b_u_f_f_e_r is the address of the new buffer.  _s_i_z_e is its size, in bytes.  _m_o_d_e
is the manner in which you wish the stream to be buffered, as follows:

    _IIOOFFBBFF   Fully buffered
    _IIOOLLBBFF   Line-buffered
    _IIOONNBBFF   No buffering

These constants are defined in the header ssttddiioo.hh.

You should  call sseettvvbbuuff() after  a stream has  been opened but  before any
data  have been  written to  or  read from  the stream.   For example,  the
following give _f_p a 50-byte buffer that is line-buffered:

    char buffer[50];
    FILE *fp;

    fopen(fp, "r");
    setvbuf(fp, buffer, _IOLBF, sizeof(buffer));

On  the other  hand, the  following  turns off  buffering for  the standard
output stream:

    setvbuf(stdout, NULL, _IONBF, 0);

sseettvvbbuuff() returns  zero if the  new buffer could  be established correctly.
It returns a value other than zero if something went wrong or if an invalid
parameter is given for _m_o_d_e or _s_i_z_e.

_E_x_a_m_p_l_e
This example uses sseettvvbbuuff() to turn off buffering and echo.

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

main(void)
{
    int c;

    if(setvbuf(stdin,  NULL, _IONBF, 0))
        fprintf(stderr, "Couldn't turn off stdin buffer\n");

    if(setvbuf(stdout,  NULL, _IONBF, 0))
        fprintf(stderr, "Couldn't turn off stdout buffer\n");

    while((c = getchar()) != EOF)
        putchar(c);
}

_S_e_e _A_l_s_o
BBUUFFSSIIZZ, ffcclloossee(), fffflluusshh(), ffooppeenn(), ffrreeooppeenn(), lliibbcc, sseettbbuuff()
ANSI Standard, section 7.9.5.6

_N_o_t_e_s
sseettvvbbuuff() affects  the buffering of an  I/O stream but does  not affect any
buffering that performed by the device  upon which the text is typed.  Some
devices  (e.g.,  /ddeevv/ttttyy)  are  buffered  by  default.  To  turn  off  the
buffering of  what a user  types, you must  both turn off  buffering on the
input stream and turn off buffering  on the device itself.  For example, to
turn off  buffering on a terminal  device, you must both  call sseettvvbbuuff() to
change the size of the input  buffering to zero, and call ssttttyy() to put the
terminal device into raw mode.
