Seeing next character in an file

Bengt Richter bokr at oz.net
Tue Jul 29 12:19:37 EDT 2003


On Tue, 29 Jul 2003 09:05:53 +0100, Richie Hindle <richie at entrian.com> wrote:

>
>[Richie]
>> seek() works perfectly with text-mode files as long as you only seek to
>> places given to you by tell().  So if Keith's peek() function had used
>> tell() and then seek()ed (sought()? 8-) back to that point like his
>> peekline() does, there would be no problem.
>
>[Bengt]
>> Can you cite a C or C++ standard section that guarantees that seek/tell
>> will work that way in text mode? (I'm not saying there isn't one, but
>> I couldn't find one quickly ;-)
>
>ANSI C, ISO/IEC 9899:1990, section 7.9.9.2: "For a text stream, either
>offset shall be zero, or offset shall be a value returned by an earlier
>call to the ftell function on the same stream and whence shall be
>SEEK_SET."
>
Thank you. It makes sense that you could retrieve and set an underlying binary position
and decode forward with arbitrary cooking, so long as that cooking either goes character
by character and leaves the binary position to right after what it has used up, or does
the equivalent by proper binary repositioning if it grabs a chunk and doesn't use all of it
for a given cooking portion, so that the next retrieval (tell) will be valid.

I guess I must have been bitten some time in the foggy past, and never recovered trust.
Now I have enough at least to use it, though I will probably still want to write a little
verification into a unit test if I'm in finicky mode. Thanks again ;-)

BTW, is there an ANSI C spec available free on line (or an older, close-enough draft)?

Regards,
Bengt Richter




More information about the Python-list mailing list