lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <COL112-W70B31F9B113D4E450DAD09C8910@phx.gbl>
Date:	Thu, 26 Mar 2009 18:33:58 -0400
From:	Adam Turk <bofh1234@...mail.com>
To:	unlisted-recipients:; (no To-header on input)
CC:	<linux-kernel@...r.kernel.org>
Subject: RE: recommended programming practices for writing (was Linux	2.6.29)


>> On Thu, 2009-03-26 at 15:03 -0400, Adam Turk wrote:
>> 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
>
> Probably because fsync() is a system call (and not a standard C lib
> function).
>
> [...]
>> 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.
>
> For a really robust app it's probably not wrong. At least one gets an
> error (e.g. "disk full") immediately and not only at fclose() time after
> (trying to) write 2GB data.
>
>> So is there a C fsync that I should add before my fclose?
>
> "fflush(fptr);" flushes all of the buffers (managed by the C-lib) of
> fptr and also delivers an error.
> fsync() is to flush the in-kernel cached pages of that file.
>
>> What is the proper way to write to files?
>
> Basically just as you do above.
>
> Bernd
 
Thank you for the tips. 
 
Thanks,
Adam
_________________________________________________________________
Quick access to Windows Live and your favorite MSN content with Internet Explorer 8.
http://ie8.msn.com/microsoft/internet-explorer-8/en-us/ie8.aspx?ocid=B037MSN55C0701A--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ