On Sun, Jun 17, 2012 at 6:15 PM, Bruno Haible <br...@clisp.org> wrote: > Paul Eggert wrote: >> On 06/12/2012 04:21 AM, Paolo Bonzini wrote: >> > perhaps we can follow the suggestion and >> > replace "if (freadahead (f))" with "if (freading(f) && !feof(f))" in >> > closein.c. >> >> Yes, thanks, I like this idea the best of those suggested so far. >> Here's a proposed patch to gnulib. > > Unfortunately, this idea will cause extra system calls for programs which > terminate without having read from stdin.
A wrongly-nonzero freadahead is a correctness problem indeed. However, in the case of close_stdin, is this important for something that happens rarely, and even then at most once in a run (and usually the time the lseek will happen anyway, because in general stdin is read in its entirety)? Not to mention that lseek(0, 0, SEEK_CUR) is one of the most optimized system calls in the kernel, possibly beaten only by gettimeofday/clock_gettime. Paolo