Re: backspace error (reading file from the end)
- From: Janne Blomqvist <foo@xxxxxxxxxxx>
- Date: Mon, 7 Aug 2006 21:36:41 +0300 (EEST)
Richard Maine wrote:
Backspacing from the current record n is performed by rewinding to the
start of the file and then performing n-1 successive READs to reach the
previous record.
The standard says nothing like this. I didn't even think it was a
particularly common implementation choice. Why would it be for
formatted files in most current systems? I'd expect the system to be
able to search backwards for the previous record terminator pretty
easily. Since I tend to avoid BACKSPACE, I guess I'm not sure on this -
I probably wouldn't have noticed. But still, such an implementation
would moderately surprise me.
As an example, what gfortran does is that it seeks BUFFER_SIZE bytes
backwards from the current file position, fills the buffer (e.g. reads
BUFFER_SIZE bytes), then scans backwards in the buffer for the record
marker (e.g. "\n" on posix). If the marker isn't found, lseek()
backwards 2*BUFFER_SIZE etc.
Like Richard, I'd be somewhat surprised if scanning forwards from the
beginning of the file is a common implementation.
--
Janne Blomqvist
.
- References:
- backspace error (reading file from the end)
- From: igor
- Re: backspace error (reading file from the end)
- From: leaf
- Re: backspace error (reading file from the end)
- From: Richard Maine
- backspace error (reading file from the end)
- Prev by Date: Re: Calling C from fortran
- Next by Date: Re: Save/restore data from a module?
- Previous by thread: Re: backspace error (reading file from the end)
- Next by thread: Re: backspace error (reading file from the end)
- Index(es):