<html><body><br><br>-----Original Message-----<br>From: fpc-pascal-admin@lists.freepascal.org<br>[mailto:fpc-pascal-admin@lists.freepascal.org] On Behalf Of James Mills<br>Sent: 05 May 2003 12:12<br>To: fpc-pascal@lists.freepascal.org<br>Subject: Re: [fpc-pascal]File errors<br><br>On Mon, May 05, 2003 at 11:52:46AM +0200, Peter Vreman wrote:<br>> > On Mon, May 05, 2003 at 11:35:14AM +0200, Peter Vreman wrote:<br>> >> > Hi,<br>> >> ><br>> >> > How do you check for file errors such as "Disk Full" before<br>attempting<br>> >> > to write out a file to disk ?<br>> >> > You can easily check if a file exists with the fileExists function...<br>> >> > Can something similar be done for other file errors ?<br>> >><br>> >> You can check with diskfree() how much space is left on a disk<br>> ><br>> > Well the program I'm developing is irc services, any particular way<br>> > you'd reccomend recoding it so it doesn't crash because of a 'Disk Full'<br>> > error ?<br>> <br>> You can turn of io-checking and check the result of ioresult<br>> <br>> {$I-}<br>> writeln(flog,logmessage)<br>> {$I+}<br>> if ioresult<>0 then<br>> writeln(stderr,'Error writing to disk');<br><br>Is this considered good programming practise ? Reason I ask is that I<br>used to use borland's turbo pascal years ago and am aware of ioresult<br>but am interested in how people before me have done it (eg: on linux<br>systems).<br><br>The program I've been developing obviously have to be 100% stable :)<br><br>You can't be 100% stable on a multi-user system unless you use a write where<br>you flush the buffer to the disc and then do the error checking - even after<br>you have written your buffer another program of higher priority might fill<br>the disk so your buffer can't get to it and your error will only come at<br>your next write. <br><br>The safest writes are to space that you already have allocated - random<br>writes. That is what databases do. In the case of a log-file, make your file<br>circular and pre-allocate it a certain size, then you will overwrite old<br>messages, but you will never fill up the disk.<br><br>This is a bit more work for people who read the log-file later, but you can<br>write a small reader to do it for them. There are lots of ways of doing<br>this, but to be safe it is best to write your new record to the circular<br>file - making sure it writes through any system buffers (a write with wait)<br>- then write the record number to the start of the file. That way your<br>log-file reader can easily show the last n records which are usually the<br>ones of interest.<br><br>On an msdros system you can make it fairly friendly by giving your circular<br>file an extension that you map to your reader - then people using it don't<br>need to be aware of how its done.<br><br></body></html>