On 06/09/2012 09:25 PM, Rich Felker wrote: > For seekable input, comparing ftello(f) and the underlying fd offset > from lseek(fileno(f),0,SEEK_CUR) would work, but that also will fail > for non-seekable input.
Thanks, that's better than what I wrote. Perhaps you could write up a patch along those lines. At least it will work for seekable files. Come to think of it, a variant might even work for seekable files. Use dup2 to move the file descriptor somewhere else. Close the fd. Keep reading until error, and count the bytes read. Then ungetc all the bytes that you read, in reverse order, and restore the file descriptor. Of course ISO C doesn't guarantee this, but it should be fairly portable in practice. > it might be better to make sense of WHY it's needed/wanted Yes, quite true, but that information wasn't communicated to the gnulib mailing list.