[m-rev.] io__read_file_as_string (was: improve `_init.c' file creation)
Simon Taylor
stayl at cs.mu.OZ.AU
Fri Dec 7 03:37:25 AEDT 2001
On 06-Dec-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 28-Nov-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > On 28-Nov-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > > 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.
> >
> > `io__read_file' is inappropriate for this kind of application
> > because the size of the input is not bounded.
>
> Well, perhaps not for the generic `cat' program,
> but I can imagine a lot of cat-like utilities
> (rot13, toupper, etc.) for which read_file_as_string
> might well be appropriate, but for which the same principle
> applies.
Any `cat'-like utility should be capable of dealing with large
input streams without failing due to lack of memory.
> > > 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.
> >
> > Applications taking user input from stdin generally don't use
> > `io__read_file' to read it.
>
> Nevertheless, the interface should allow this use of io__read_file_as_string.
The interface should not encourage the creation of broken software
with unnecessary fixed limits. Allowing io__read_file_as_string to
handle partial reads creates a false perception of robustness.
The proper solution for programs which read enough data that
partial reads are an issue is to read the data in smaller chunks.
The interface should also be consistent with all of the other input
predicates.
Simon.
--------------------------------------------------------------------------
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