Re: ttyS1 hangs, cua1 works fine

Gert Doering (gert@greenie.muc.de)
Mon, 6 Apr 1998 15:19:16 +0200 (MEST)


Hi,

Richard B. Johnson wrote:
> > > 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.
[..]
> 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.

No, this is wrong. There can very well be some *bits* in the flag words
that are "unnamed" (I'd prefer to call them not "unnamed" but "not
portable"). For example, the hardware flow control flags on about every
system around fall into that category.

> 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).

Your code clears all flags that might be set in the control words. This
is bad, as you don't know them all.

> This code is correct.

Correct, but stupid, because very non-portable.

gert

-- 
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             gert@greenie.muc.de
fax: +49-89-35655025                        gert.doering@physik.tu-muenchen.de

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