bug-gnulib
[Top][All Lists]
Advanced

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

Re: address@hidden: Re: CVS commit: pkgsrc/devel/m4]


From: Joerg Sonnenberger
Subject: Re: address@hidden: Re: CVS commit: pkgsrc/devel/m4]
Date: Wed, 25 Jul 2007 15:59:24 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

On Wed, Jul 25, 2007 at 07:24:56AM -0600, Eric Blake wrote:
> > That leaves the question
> > whether the much less intrusive:
> >     off_t cur_pos;
> >     cur_pos = ftello(stdio);
> >     lseek(fileno(stdin), cur_pos, SEEK_SET);
> > isn't a much better solution?
> 
> No, because now that the position of the underlying fd does not match the
> optimized position that stdin has recorded, any further use of stdin will
> be broken.  M4 uses fflush(stdin) immediately before spawning a child
> process with the syscmd macro, but when the child is complete, m4 again
> uses stdin, so m4 must not do anything that confuses stdin by manipulating
> fileno(stdin) behind stdio's back.

OK, I'm still not fully sure I understand all parts of the problem. The
flushing happens in debug_flush_files, right? When the called programs
reads from stdin itself, is m4 supposed to see such changes? This would
mandate an explicit after the program is executed as well. What happens
if the program modifies the regular file opened for stdin? If I
understand the implications correctly, the only correct approach would
be to disable buffering before calling the program and reenable that
afterwards. That should be portable as well. E.g.:

        off_t pos;
        pos = ftello(stdin);
        setvbuf(stdin, NULL, _IONBF, 0);
        fseeko(stdin, pos, SEEK_SET);
        if (isatty(fileno(stdin))
                setvbuf(fileno(stdin), NULL, _IOLBF, 0);
        else
                setvbuf(fileno(stdin), NULL, _IOFBF, 0);

Joerg




reply via email to

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