This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] Fix second half of libstdc++/6745
- From: Jonathan Lennox <lennox at cs dot columbia dot edu>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, libstdc++ at gcc dot gnu dot org
- Date: Mon, 18 Nov 2002 15:44:06 -0500
- Subject: Re: [v3] Fix second half of libstdc++/6745
- References: <3DD948CF.1090103@unitus.it>
Paolo Carlini writes:
> the below, tested x86-linux, approved by Benjamin, fixes the
> interactive part of the PR.
> +#ifdef _GLIBCPP_HAVE_ISATTY
> + size_t __size = isatty(0) ? 1 : static_cast<size_t>(BUFSIZ);
> +#else
> + size_t __size = 1;
> +#endif
One problem with this. __copy_streambufs is a general function -- it's not
just used to copy from stdin. However, this patch conditionalizes the
function's buffer size on isatty(0), even though in many cases when it's
used, (i.e., copying from a readable buffer other than cin->rdbuf()), the
nature of stdin is irrelevant.
Is dynamic_cast<> allowed in libstdc++? One possibility that might work for
the _GLIBCPP_HAVE_ISATTY block is something like this:
size_t __size;
basic_filebuf<_CharT, _Traits>* __fbin =
dynamic_cast<basic_filebuf<_CharT, _Traits>*>(__sbin);
if (__fbin != NULL && isatty(__fbin->_M_file.fd())) {
__size = 1;
}
else {
__size = static_cast<size_t>(BUFSIZ);
}
This is just a sketch -- basic_filebuf::_M_file is protected, so a friend
declaration to __copy_streambufs would be needed. Alternately,
basic_filebuf could acquire a public _M_is_tty() method. (Would there be
binary compatibility issues with this?)
--
Jonathan Lennox
lennox at cs dot columbia dot edu