[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yesno module consumes too much input

From: Bruno Haible
Subject: Re: yesno module consumes too much input
Date: Sat, 18 Aug 2007 19:53:39 +0200
User-agent: KMail/1.5.4

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,

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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]