termios: merge the termios baud definitions

Now all platforms unconditionally use the "sane" definitions of the
termios baud constants. Unify them into a common file.

Note: I have made them explicitly unsigned to avoid problems with
compiler warnings for comparisons of unequal signedness or
similar. These constants were historically octal on most platforms,
and so unsigned by default.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
This commit is contained in:
H. Peter Anvin (Intel) 2025-06-11 18:35:40 -07:00 committed by Adhemerval Zanella
parent bbbaf50b2a
commit ad37ecd579
5 changed files with 48 additions and 77 deletions

View File

@ -1,4 +1,4 @@
/* termios baud rate selection definitions. Linux/generic version.
/* termios baud rate selection definitions. Universal version for sane speed_t.
Copyright (C) 2019-2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@ -20,37 +20,44 @@
# error "Never include <bits/termios-baud.h> directly; use <termios.h> instead."
#endif
#define B0 0U
#define B50 50U
#define B75 75U
#define B110 110U
#define B134 134U
#define B150 150U
#define B200 200U
#define B300 300U
#define B600 600U
#define B1200 1200U
#define B1800 1800U
#define B2400 2400U
#define B4800 4800U
#define B7200 7200U
#define B9600 9600U
#define B14400 14400U
#define B19200 19200U
#define B28800 28800U
#define B33600 33600U
#define B38400 38400U
#define B57600 57600U
#define B76800 76800U
#define B115200 115200U
#define B153600 153600U
#define B230400 230400U
#define B307200 307200U
#define B460800 460800U
#define B500000 500000U
#define B576000 576000U
#define B614400 614400U
#define B921600 921600U
/* POSIX required baud rates */
#define B0 0U /* Hang up or ispeed == ospeed */
#define B50 50U
#define B75 75U
#define B110 110U
#define B134 134U /* Really 134.5 baud by POSIX spec */
#define B150 150U
#define B200 200U
#define B300 300U
#define B600 600U
#define B1200 1200U
#define B1800 1800U
#define B2400 2400U
#define B4800 4800U
#define B9600 9600U
#define B19200 19200U
#define B38400 38400U
#ifdef __USE_MISC
# define EXTA B19200
# define EXTB B38400
#endif
/* Other baud rates, "nonstandard" but known to be used */
#define B7200 7200U
#define B14400 14400U
#define B28800 28800U
#define B33600 33600U
#define B57600 57600U
#define B76800 76800U
#define B115200 115200U
#define B153600 153600U
#define B230400 230400U
#define B307200 307200U
#define B460800 460800U
#define B500000 500000U
#define B576000 576000U
#define B614400 614400U
#define B921600 921600U
#define B1000000 1000000U
#define B1152000 1152000U
#define B1500000 1500000U
@ -59,5 +66,7 @@
#define B3000000 3000000U
#define B3500000 3500000U
#define B4000000 4000000U
#define B5000000 5000000U
#define B10000000 10000000U
#define __MAX_BAUD 4294967295U

View File

@ -20,6 +20,8 @@
# error "Never include <bits/termios.h> directly; use <termios.h> instead."
#endif
#include <bits/termios-baud.h>
/* These macros are also defined in some <bits/ioctls.h> files (with
numerically identical values), but this serves to shut up cpp's
complaining. */
@ -285,45 +287,6 @@ struct termios
/* Input and output baud rates. */
speed_t __ispeed, __ospeed;
#define B0 0 /* Hang up. */
#define B50 50 /* 50 baud. */
#define B75 75 /* 75 baud. */
#define B110 110 /* 110 baud. */
#define B134 134 /* 134.5 baud. */
#define B150 150 /* 150 baud. */
#define B200 200 /* 200 baud. */
#define B300 300 /* 300 baud. */
#define B600 600 /* 600 baud. */
#define B1200 1200 /* 1200 baud. */
#define B1800 1800 /* 1800 baud. */
#define B2400 2400 /* 2400 baud. */
#define B4800 4800 /* 4800 baud. */
#define B9600 9600 /* 9600 baud. */
#define B7200 7200 /* 7200 baud. */
#define B14400 14400 /* 14400 baud. */
#define B19200 19200 /* 19200 baud. */
#define B28800 28800 /* 28800 baud. */
#define B38400 38400 /* 38400 baud. */
#ifdef __USE_MISC
# define EXTA 19200
# define EXTB 38400
#endif
#define B57600 57600
#define B76800 76800
#define B115200 115200
#define B230400 230400
#define B460800 460800
#define B500000 500000
#define B576000 576000
#define B921600 921600
#define B1000000 1000000
#define B1152000 1152000
#define B1500000 1500000
#define B2000000 2000000
#define B2500000 2500000
#define B3000000 3000000
#define B3500000 3500000
#define B4000000 4000000
};
#define _IOT_termios /* Hurd ioctl type field. */ \

View File

@ -151,7 +151,6 @@ sysdep_headers += \
bits/struct_stat.h \
bits/struct_stat_time64_helper.h \
bits/syscall.h \
bits/termios-baud.h \
bits/termios-c_cc.h \
bits/termios-c_cflag.h \
bits/termios-c_iflag.h \

View File

@ -35,6 +35,7 @@ typedef unsigned int tcflag_t;
/* c_cflag bit meaning */
#include <bits/termios-c_cflag.h>
#ifdef __USE_MISC
#define __B0 0000000 /* hang up */
#define __B50 0000001
#define __B75 0000002
@ -53,9 +54,8 @@ typedef unsigned int tcflag_t;
#define __B38400 0000017
#include <bits/termios-cbaud.h>
#ifdef __USE_MISC
# define EXTA __B19200
# define EXTB __B38400
# define __EXTA __B19200
# define __EXTB __B38400
# define BOTHER __BOTHER
#endif

View File

@ -22,8 +22,8 @@ subdir := termios
include ../Makeconfig
headers := termios.h bits/termios.h sys/ttydefaults.h sys/termios.h \
sys/ttychars.h
headers := termios.h bits/termios.h bits/termios-baud.h \
sys/ttydefaults.h sys/termios.h sys/ttychars.h
routines := speed cfsetspeed tcsetattr tcgetattr tcgetpgrp tcsetpgrp \
tcdrain tcflow tcflush tcsendbrk cfmakeraw tcgetsid