Paul Eggert replied to Eric Blake: > > is it reasonable to have yesno install an atexit > > handler on first invocation? If the handler is not present, > > then stdin was never used (at least not by yesno). > > Yes, that sounds reasonable to me.
Still, I haven't understood what is so special about the 'yesno' function. The code in close_stdin() is needed if _any_ input has been done on stdin, no? In that case, rather than modifying 'yesno', 'readline', 'getline', 'getpass' etc., wouldn't it be more reliable to call close_stdin() always, and optimize close_stdin() to do nothing if stdin is still in the initial state (i.e. has no in-memory buffer). This can be done through in-memory tests, such as essentially (cf. lib/fseeko.c): #if defined _IO_ferror_unlocked /* GNU libc, BeOS */ if (fp->_IO_read_end == fp->_IO_read_ptr) #elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ if (fp->_r == 0) #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */ if (fp->_ptr == NULL || fp->_cnt == 0) #endif return; Bruno