mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* recommended programming practices for writing (was Linux 2.6.29)
@ 2009-03-26 19:03 Adam Turk
  2009-03-26 19:34 ` Bernd Petrovitsch
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Adam Turk @ 2009-03-26 19:03 UTC (permalink / raw)
  To: linux-kernel


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 {
  fprintf(fptr,"%s\n",datablock);
  while(!writeouput(datablock,amount,tax)) {
    getnext(dtablock)
    fprintf(fptr,"%s\n",datablock);
  }
  fclose(fptr);
}

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?

Thanks,
Adam

_________________________________________________________________
Hotmail® is up to 70% faster. Now good news travels really fast.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-03-26 22:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-26 19:03 recommended programming practices for writing (was Linux 2.6.29) Adam Turk
2009-03-26 19:34 ` Bernd Petrovitsch
2009-03-26 22:33   ` Adam Turk
2009-03-26 19:35 ` Leon Woestenberg
2009-03-26 22:32   ` Adam Turk
2009-03-26 22:40 ` J.A. Magallón

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®