[fpc-pascal]File errors

James Mills prologic at prologitech.com
Mon May 5 13:34:05 CEST 2003


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

Thanks for that response, I guess is isn't possible to do on a
multi-user system as you said. However a circular file would mean you'd
only have a log-file history of length x ... Interesting way of doing
it, would mean you'd never be able to view any logs beyond x since they
don't exist.

cheers
James




More information about the fpc-pascal mailing list