Re: ttyS1 hangs, cua1 works fine

Theodore Y. Ts'o (tytso@MIT.EDU)
Mon, 6 Apr 1998 14:46:18 -0400


Date: Mon, 6 Apr 1998 08:32:28 -0400 (EDT)
From: "Richard B. Johnson" <root@chaos.analogic.com>

> I can only strongly recommend against just "bzero()"'ing a structure that
> *might* contain some flags that you don't know about.
>
> Explicitely clear the flags that you want to have cleared, explicitely set
> those that you want to be set, *KEEP* the rest unchanged.
>
> (But now we're getting offtopic on linux-kernel, that's just a matter of
> defensive programming -- if you do it your way, it *will* break on strange
> systems like SCO).

All of this structure that is allowed to be known to the programmer is
defined in the header file.

It is only this entire known structure that is cleared. If there are
invisible portions of this structure, they will be at the end, not defined
in the header file, and not interpreted by the sizeof operator.

This code is correct.

This code may be correct today, but it's not portable. That was what
Gert was saying. For example, POSIX-compliant OS is free to define new
termios flags, some of which must be set for normal operation.

For example, that as an exampel the (fictional) termios cflag
C_DONT_RANDOMLY_LOSE --- which is used to implement RFC-748, the Telnet
Randomly-Lose option. :-)

It's not a structure member, but a new flag defined in the termios
structure. If you just bzero the structure and set the flags you want,
you might end up clearing the C_DONT_RANDOMLY_LOSE option, with
disastrous effects.

That's why the well-written POSIX-complaint program will do a
tcgetattr(), set or clear the flags the programmer wants, and then do a
tcsetattr(). The POSIX specification very explicitly and strongly
contains this suggestion.

- Ted

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu