CBREAK in S5/~ICANON in V7/4.x

Guy Harris guy at sun.uucp
Mon Jul 22 09:43:19 AEST 1985


(Posted to "net.unix" and "net.unix-wizards" as well, because this seems to
be one of the Most Asked Questions Of All Time.)

> >Many of the programs I'm trying to port require CBREAK and no
> >ECHO modes.  How is this done under SVR2?
> 
> In Unix System V, the terminal modes have quite a lot of flexibility in
> determining when a read() can complete.  They are documented in excruciating
> detail in termio(7) (in the UNIX System Administrator's Manual, alas, not
> the Programmer's Manual where they belong - gh).
>
> What you basically want to do is turn off ICANON (in the "c_lflag" word -
> gh) and set VMIN and VTIME as your application requires.  CBREAK is, I
> believe, MIN=1, TIME=0.

This is correct.

> "The MIN and TIME values are stored in the position for the EOF and EOL
> characters, respectively.  The time value represents tenths of seconds."
> To turn off echo modes, turn off that bit (also in the "c_lflag" word - gh),
> as well.  (It may be that this is automatic, but I don't think so.)

It isn't.  You have to disable echoing and canonicalization independently.

> The parameters are changed via ioctl() operations.  I strongly recommend
> using TCSETAW instead of TCSETA, because some computer systems actually
> implement a no-wait mode stomper, which can garble some characters being
> output at the time.
> -- 
> Ron Heiby

In the V7 driver (straight and as modified in 4.xBSD), "TIOCSETP" (or
"stty", which just does a "TIOCSETP") waits for output to drain and flushes
input.  "TIOCSETN" does not wait and does not flush input or output.

In the S5 (and S3) driver, "TCSETA" acts like "TIOCSETN", "TCSETAF" acts
like "TIOCSETP", and "TCSETAW" is like "TCSETAF" only it doesn't flush the
input.

For the benefit of people moving S3/S5 programs to V7/4.xBSD, you can
probably ignore whatever VMIN and VTIME are set to (unless VMIN is set to 0,
in which case VTIME acts as a read timeout).  Turning off ICANON is
equivalent to turning on CBREAK; turning off ISIG is equivalent to setting
the interrupt and quit characters to '\377' (disabling them, in other
words); turning off ECHO is, surprise surprise, equivalent to turning off
ECHO.

	Guy Harris



More information about the Comp.unix.wizards mailing list