fflush

fflush and 'no disk space left'

I'm writing a program, some kind of database. While I was reading manual of fclose(3) I found that it calls fflush(3) to flush FILE* buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call fsync(2)). Because I'm writing a DB it is obvious that I want to prevent data loss. If there is no disk space an...

Difference between fflush and fsync

I thought fsync() does fflush() internally so using fsync() on a stream is OK. But i am getting unexpected result when executed under network I/O. My code snippet: FILE* fp = fopen(file,"wb"); /* multiple fputs() call like: */ fputs(buf, fp); ... ... fputs(buf.c_str(), fp); /* get fd of the FIL...

Using fflush(stdin)

So a quick google search for fflush(stdin) for clearing the input buffer reveals numerous websites warning against using it. And yet that's exactly how my CS professor taught the class to do it. How bad is using fflush(stdin)? Should I really abstain from using it, even though my professor is using it and it seems to work flawlessly? ...

Keeping 'almost complete' logs even when system crashes

We have a c++ application (console) that runs on windows and unix. This application used output files to output verbose log files of system calls/prints/etc. The prblem is, that in certain occasion we might get signal 11/2 after new features are added. Now whenever, that happenes, we do not get 'almost complete' information from log f...

fflush and while loop

Hello, I have been trying to use fflush to make a progress bar. To test fflush, I wrote the small code below. It works as it supposed to when I uncomment "sleep(1);" but it works in an unexpected way if it remains commented out. It prints the first dash, waits than prints all remaining 9 of them and quits. I don't understand why it...

fflush(stdout) in c

Right when I am at fflush(stdout) and I break there in GDB, can I know what is there in stdout before I actually print it? How can I know what is there in stdout at any point in time? ...