Skip to content

Termios speed setting problem #81

@hpax

Description

@hpax

Since glibc 2.42 Linux glibc supports arbitrary baud rates directly; several other Unices have done that for a long time.

The code in serial.c has several serious problems, however:

  1. Manipulating c_cflag directly is not the correct way to set baud rates for any system; that was the method used with the termio (not termios) interface, but termios has always required the use of cfset[io]speed().
  2. If the Bxxx constants match the respective xxx values then it should be safe to use them as integers directly. For Linux specifically, you can simply test for B300 == 300.
  3. Don't use TIOCGSERIAL for these newer systems; using TIOCGSERIAL breaks other applications.
  4. Glibc 2.42 added cfset[io]baud() which is explicitly defined as numeric, if you don't trust relying on testing the Bxxx constants; however, that will not yet work on other Unices.

The stty code in GNU coreutils has been augmented with autodetection of supported speeds to a specific platform. You might find that interesting as an example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions