Re: ttyS1 hangs, cua1 works fine

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


On Mon, 6 Apr 1998, Gert Doering wrote:

> Hi,
>
> Richard B. Johnson wrote:
> > /*
> > * Set to dumb RAW mode with no echo and no character interpretation.
> > */
> > memset(&io_mod, 0x00, sizeof(io_mod)); /* bzero() is obsolete */
> > io_mod.c_cflag = B38400|CS8|CREAD|CLOCAL;
> > io_mod.c_iflag = IGNBRK|IGNPAR;
> > io_mod.c_cc[VMIN] = (cc_t) 1;
> > io_mod.c_cc[VTIME] = (cc_t) 1;
>
> 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.

Note that, although the alignment of structure members could be anything,
and not guaranteed, there cannot be any holes, i.e., unnamed members. The
only unnamed members (if any) have to be put at the end, after the known
members.

This code takes a blank, i.e., zeroed structure, and sets the required
parameters into the required fields. Therefore, it does not leave any
fields undefined (whatever was on the stack).

This code is correct.

Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.92 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

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