[lkml]   [2009]   [Mar]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjectrecommended programming practices for writing (was Linux 2.6.29)

I have been reading the Linux 2.6.29 thread with interest. I have written several (10 or so) C programs that write large amounts of data (between 1 and 2 GB file sizes are common). A snippet of code looks like this:

if((fptr = fopen(outfilename,"w")) == NULL) {
printf("File %s could not be created\n", outfilename);
else {
while(!writeouput(datablock,amount,tax)) {
I learned C about 15 years ago and there was no mention of a fsync. My C book doesn't mention fsync either. Granted I have written only 25-30 applications in the last 15 years or so so I am not an expert C programmer.

From what Linus posted about git and checking the return from fclose I think I going to start doing that. I also think I am going to start checking the return from fprintf and maybe write to a /tmp/file and then rename it.

So is there a C fsync that I should add before my fclose?
What is the proper way to write to files?

Is what I am thinking about doing something that would be good or is it just a lack of my understanding the problem?


Hotmail® is up to 70% faster. Now good news travels really fast.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at
 \ /
  Last update: 2009-03-26 20:09    [from the cache]
©2003-2014 Jasper Spaans. hosted at Digital Ocean