setvbuf

J

j0mbolar

is using _IONBF with setvbf the general way of getting
an unbuffered stream in a standardized way? or are system
specific functions generally favored over c89's setvbuf?
 
J

Jens.Toerring

j0mbolar said:
is using _IONBF with setvbf the general way of getting
an unbuffered stream in a standardized way?
Yes.

or are system specific functions generally favored over c89's
setvbuf?

Since it unbuffers the standard C functions (i,e, fprintf(),
fwrite() etc.) there probably isn't a system specific way to
unbuffer them. But unbuffering the C functions might nor do
everything you want, the system can do further buffering on
several levels (e.g. not immediately writing things to a
file but keeping it in some kernel buffers and even a write
to a hard disk could again go through some buffers on the
hard disk), and to switch that off you would need system
specific functions.
Regards, Jens
 
D

Dan Pop

In said:
is using _IONBF with setvbf the general way of getting
an unbuffered stream in a standardized way? or are system
specific functions generally favored over c89's setvbuf?

You're confused. There are multiple buffering levels on most hosted
platforms. setvbuf controls the buffering performed at the level of the
<stdio.h> functions and there is no other alternative (except for setbuf,
which is a less flexible setvbuf). The OS itself typically performs its
own buffering, and this buffering is controlled with system specific
functions. Some devices also do their own buffering and this buffering
may not be controllable by the application code.

This explains why, on many platforms, even if stdin buffering is
turned off with setvbuf, reading from stdin still blocks until the
newline key is pressed (assuming that stdin is connected to the
controlling terminal).

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top