[v3] Fix second half of libstdc++/6745

Jonathan Lennox lennox@cs.columbia.edu
Mon Nov 18 12:44:00 GMT 2002


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



More information about the Gcc-patches mailing list