[m-rev.] io__read_file_as_string (was: improve `_init.c' file creation)
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Nov 28 17:57:01 AEDT 2001
On 28-Nov-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > > + % XXX Why does `io__read_file_as_string' return a separate
> > > + % status and result, rather than an `io__res(string)'?
> >
> > The reason is to ensure that, in the case when some characters are
> > successfully read and then an I/O error occurs, the part of the file
> > that was successfully read can be returned.
>
> When is that behaviour useful?
When the error is something such as EINTR.
When implementing programs such as `cat', which should output all that
it successfully reads before reporting a read error.
When the error occurs because the input file is `stdin',
and the user's dialup connection has just been disconnected
due to a Telstra fault. The data may be hard for the user
to reproduce, so the program should not just throw it away.
> If an error occurs in the middle
> of a read, can the part that was read be trusted?
Yes, to the same degree that any prior successful read can be trusted.
> It also doesn't
> force the user to check for errors before using the result like all
> the other input predicates do (including `io__read_file'). It might be
> better to use a different result type like the one below,
I could live with that.
> but I think
> the best solution is just to return an `io__res(string)' and throw away
> the partially read data.
I couldn't live with that.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list