IonicWind Software

IWBasic => General Questions => Topic started by: Hootie on October 24, 2008, 06:09:49 PM

Title: Forcing a buffer flush when writing a file?
Post by: Hootie on October 24, 2008, 06:09:49 PM
Is there any way in Ebasic to do a fflush()?  I'm writing an error logging module and I want to keep the log file buffer flushed in case of program crash so all the messages will be in the log up to the crash.
Title: Re: Forcing a buffer flush when writing a file?
Post by: Ionic Wind Support Team on October 24, 2008, 06:23:37 PM
The simplest way is just to close the file after each write.

OpenFile(LogFile, LogFileName, "A")
...write
CloseFile(LogFile)

Which is a method I use on a larger server project.

Of course if you just want to use the Windows API both the FILE and BFILE variables are a handle to the open file created with CreateFile:

Declare import, FlushFileBuffers(uint hFile),int
...
FlushFileBuffers(LogFile)

Title: Re: Forcing a buffer flush when writing a file?
Post by: Hootie on October 24, 2008, 08:22:32 PM
Thanks!