Subj : Committing file changes To : Coridon Henshaw From : David Noon Date : Mon Aug 14 2000 01:23 pm Hi Coridon, Replying to a message of Coridon Henshaw to All: CH> What's the proper way to 'checkpoint' an open file so as to ensure CH> that the file's control structures are consistant on disk? I would CH> have thought that calling fflush() after every file write would be CH> sufficient, but a recent trap proved that calling fflush() after file CH> writes was no protection against CHKDSK truncating the file well CH> before the last write. I suppose I could close and reopen the file CH> after every update, but I was hoping to find a more elegant solution. How low do you want to go? Firstly, you should not be doing buffered I/O if your updates must be committed immediately, so you should not use fopen() and fwrite() without a setbuf() call to suppress buffer allocation. Better yet, you should consider using open() and write() instead, and use the UNIX-like unbuffered I/O routines. If you want to be a real fundamentalist, you should use DosOpen() and DosWrite() without risking the CRTL tampering with your data flow. Moreover, if your data resources are critically important then you should be handling any traps that occur in your program and cleaning up the critical data resources in an orderly manner. This is far and away the most professional approach to the situation. About the only things you can't handle are kernel level traps and power outages. In your situation, I would have used the second facility before considering any intermediate commits. Another consideration is choice of language. The more robust languages have RTL's that perform a formal close on all files, even when the application code fails to handle an error. This is because their RTL's catch all unhandled application errors, and they keep track of all files opened through the RTL. Hence, either PL/I or COBOL would have been a far better choice of language than C/C++, if you are not rolling your own trap handler. The ultimate moral is: code your own trap handler, or use a language that provides one built-in. Regards Dave --- FleetStreet 1.25.1 * Origin: My other computer is an IBM S/390 (2:257/609.5) .