www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/18/06:33:38

Date: Tue, 18 May 1999 13:31:24 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: djgpp-workers AT delorie DOT com
Subject: termios and raw mode
Message-ID: <Pine.SUN.3.91.990518132931.24330B-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

While working on building and testing GDB 4.18, I noticed a problem
in termios.  Here's a fragment from the termios function that gets
called instead of `_write' for file handles that are hooked by termios:

  if ((devmod & _DEV_CDEV) && (devmod & (_DEV_STDIN|_DEV_STDOUT)))
    {
      /* character device */
      if (devmod & _DEV_RAW)
	*rv = __libc_termios_write_raw_tty (handle, buffer, count);
      else
	*rv = __libc_termios_write_cooked_tty (handle, buffer, count);
      return 1;
    }

(`devmod' is the device information word returned by
`_get_dev_info').  There is a similar fragment in the function that
is called instead of `_read'.

I think it is wrong to use the raw input/output simply because the
device is in raw mode.  The reason is that the device might be in raw
mode because some other handle connected to it was switched to binary
mode, but the application might still expect other handles connected
to that device to work in the default cooked mode.

The most striking case where the above code misfires is in a debugger.
As soon as the debuggee switches its stdin to binary mode, the
debugger's *output* will suddenly begin using binary mode too (e.g.,
NL isn't converted to CR-LF).  I think this is wrong.

A simple solution would be to replace this if clause:

      if (devmod & _DEV_RAW)

 with this:

      if ((devmod & _DEV_RAW) && (__file_handle_modes[handle] & O_BINARY))

Does anybody see any harm that would be done by this change?  In
particular, Mark, could you please see if Bash ever switches one of
its handles to binary mode, and if so, will this somehow affect it?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019