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? 2 2038
j0mbolar <j0******@engin eer.com> wrote: 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
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
In <2d************ **************@ posting.google. com> j0******@engine er.com (j0mbolar) writes: 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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Keith Doyle |
last post by:
I'm curious if setvbuf behavior is known to be undefined with regards
to effects it may have on the file pointer. I've found that the
following code works different on AIX 4.3.3 xlc and FreeBSD gcc 2.95.2
19990314 than it does on SCO 5.0.4 cc or Linux gcc egcs-1.1.2 19991024.
This is a bit curious as here's a gcc example that works one way and
one that works the other, and I would think the relevant code is in
libc/glibc.
This is what...
|
by: Ramprasad A Padmanabhan |
last post by:
I am running a program within another and reading the output. My problem
is that all outputs are delayed because of bufferring
Can I tell printf to print all outputs immediately and not buffer it
Thanks
Ram
|
by: grunes |
last post by:
I wish to fread a few thousand bytes at a time in turn from several
very large files from a DVD data disk, under Redhat Fedora Linux.
When this is done the DVD drive wastes a lot of time and almost shakes
itself to pieces.
I tried using setvbuf, with large buffers, e.g. (example only, not
checked):
#include <stdio.h>
|
by: JG |
last post by:
Does anyone know a standard (or supported on Linux, Mac, Win32) way to
clear a read stream buffer (standard ANSI C file stream)?
I would even settle for a platform specific way of doing it.
And no, I know I can use direct low level I/O or non-buffered to do
reads, but for my app, I need the buffering. I can implement myself,
but this is not optimal.
Example, I open a read only file using fopen(). I periodically know
|
by: kernelxu |
last post by:
hi, everyone.
now, I'am confused on such a problem:
function setbuf(stdin, NULL) or setvbuf(stdin, NULL, _IONBF, 0)
can set the stadard input stream unbuffered.
however, why does my program work like buffered?
the program is below
| |
by: santosh |
last post by:
Which situations call for the use of setvbuf(), specifically when you
supply the buffer yourself? What is the advantage of an user specified
buffer over an automatically allocated one? Can we call setvbuf() on
the predefined streams, immediatly upon start of main()? How often is
this function used in typical C programs?
Thanks.
|
by: sitko |
last post by:
Hi,
I'm creating a quick utility which will copy one file into another, but I need it to have the ability to select out certain lines not to copy.
I figured I'd use fread/fwrite but set the buffering size to a line with "setvbuf", here is the code I was going to use as a skeleton for this:
#include <stddef.h>
#include <stdio.h>
#define FAIL 0
#define SUCCESS 1
|
by: Jag |
last post by:
I've read parts of K&R's ANSI C v2 and this is what their cat looked
like but when I compared the speed of this code to gnu cat, it seems
very slow. How do I optimize this for greater speeds? is there an
alternative algorithm?
void catfile(FILE *in, FILE *out) {
register int num_char;
/*Get characters*/
while ((num_char = getc(in)) != EOF) {
|
by: vippstar |
last post by:
Is there a memory leak in this particular program:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("Hello, world\n");
if(setvbuf(stdout, NULL, _IONBF, 0) != 0) {
perror("setvbuf");
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |