Hi Eric, Here is the relevant code from modules/m4.c in CVS HEAD:
508 /* POSIX requires that if m4 doesn't consume all input, but stdin is 509 opened on a seekable file, that the file pointer be left at the 510 next character on exit (but places no restrictions on the file 511 pointer location on a non-seekable file). It also requires that 512 fflush() followed by fseek() on an input file set the underlying 513 file pointer. However, fflush() on a non-seekable file can lose 514 buffered data, which we might otherwise want to process after 515 syscmd. Hence, we must check whether stdin is seekable. We must 516 also be tolerant of operating with stdin closed, so we don't 517 report any failures in this attempt. The stdio-safer module and 518 friends are essential, so that if stdin was closed, this lseek is 519 not on some other file that we have since opened. Mingw has bugs 520 when using fseek on text files, so we only strive for POSIX
521 behavior when we detect a UNIX environment. */ 522 #if UNIX 523 if (lseek (STDIN_FILENO, 0, SEEK_CUR) >= 0 524 && fflush (stdin) == 0) 525 { 526 fseek (stdin, 0, SEEK_CUR); 527 } 528 #endif /* UNIX */ 529 } On 2 Apr 2007, at 14:24, Eric Blake wrote:
m4 already called fseek, but currently it just discarded the results; can you step through m4_sysval_flush todetermine if the fseek was accurately returning the offset in the middleof the input rather than at the end?
Okay, at line 524 fflush returns -1 and sets errno to EBADF. Looking at the man page for Mac OS fflush, it is only supposed to work for output streams where it flushes the write buffer. The equivalent function for input streams is fpurge. And indeed, if I change 524 to call "fpurge (stdin)", the test passes.
If it does work, how many other gnulib-using programs would benefit from a fix?
At worst we need an autoconf test to see whether fflush works on stdin,but maybe all that is needed is to call fpurge when present, and fallback
to fflush otherwise? Cheers, Gary -- ())_. Email me: [EMAIL PROTECTED] ( '/ Read my blog: http://blog.azazil.net / )= ...and my book: http://sources.redhat.com/autobook `(_~)_ Join my AGLOCO Network: http://www.agloco.com/r/BBBS7912
PGP.sig
Description: This is a digitally signed message part