setbuf
The virtual function
setbuf
is called by user code to offer an
array for use as a holding area.
It can also be used to turn off buffering.
streambuf* fctbuf::setbuf(char* b, int len)
{
if ( base() ) return 0 ;
if ( b!=0 && len > sizeof(small) ) {
// set up holding area
setb(b,b+len) ;
}
else {
// Use a one character array to achieve
// "unbuffered" actions.
setb(small,small+sizeof(small)) ;
}
setp(0,0) ; // put area
setg(0,0,0) ; // get area
return this ;
}
The actions of this function are:
-
base()
points to the first character of the holding area.
If a holding area has already been set up (base
non-zero) a new one cannot be established and
setbuf()
returns a null pointer as an error indication.
-
If an array is supplied and is sufficiently large,
setb()
is called to set up the pointers to the holding area.
Its first argument becomes
base,
the first
char
of the holding area, and its second becomes
ebuf,
the
char
after
the last.
Otherwise the
fctbuf
will become unbuffered.
This is noted by setting up a one character holding area.
-
Finally the pointers related to the put area are set to 0 by
setp()
and the pointers related to the get area are set to 0 by
setg().
Next topic:
overflow
Previous topic:
Deriving new streambuf classes
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005