[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: stdin seekable failure
From: |
Bruno Haible |
Subject: |
Re: stdin seekable failure |
Date: |
Sat, 28 Apr 2007 09:20:46 +0200 |
User-agent: |
KMail/1.5.4 |
Eric Blake wrote:
> The workaround would be
> to see if lseek returns a non-negative number; and if so, read the
> internals of the FILE to see how many bytes remain in the read buffer (the
> default buffer size is 4k); then since the file is seekable, temporarily
> swap the fd into O_BINARY mode, reread the buffer, count how many raw \n
> occur, then convert the fd back to O_TEXT before returning the corrected
> answer. The workaround would also have to handle ^Z.
Indeed, that should work. (If the number of bytes in the buffer is n,
you might need to go back by up to 2*n bytes.) Bravo! Since this effort is
for only one implementation, it appears doable and maintainable.
Bruno