Re: KI_FILE count precondition

"Bernd Schoeller" <[email protected]>
Newsgroups gmane.comp.lang.eiffel.gobo.general
Organization ETH Zurich
Message-ID <[email protected]>
On Thu, 18 Jan 2007 17:30:19 +0100, Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]>  
wrote:

> Bernd Schoeller wrote:
>> Can anybody motivate for me the reason of the 'is_closed' precondition  
>> in
>> KI_FILE?
>
> If the file is not closed, then we might be writing
> to it. The new characters may still be in the buffer
> or already on disk. What does `count' means in that
> case?

Well - on an open file, the count should be exactly what is visible  
through the open file handle. I understand that there are potential  
problems with concurrent access to the same file, but I do not see how  
these might get resolved by requiring only to measure the size of a closed  
file.

> If you want to know the size of a file on disk,
> use KL_SHARED_FILE_SYSTEM.file_system.file_count.

The code in question reads the content of file into a string, a common  
task that should be reasonably easy to implement.

Currently, it looks as follows:

file.reset(filename)
filesize := file.count
file.open_read
if file.is_open_read then
   file.read_string(filesize)
   s := file.last_string
   file.close
end

This looks a little complex to me and still has problems. I am a little  
afraid to just call

   file.read_string(Platform.Maximum_integer)

as, looking at the implementation in KL_TEXT_INPUT_FILE, this might create  
a buffer of that size.

It would be best if there was a 'read_string(-1)' that would just read in  
everything available.

Bernd
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.