]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
termios: merge the termios baud definitions
authorH. Peter Anvin (Intel) <hpa@zytor.com>
Thu, 12 Jun 2025 01:35:40 +0000 (18:35 -0700)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 17 Jun 2025 12:11:38 +0000 (09:11 -0300)
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>
bits/termios-baud.h [moved from sysdeps/unix/sysv/linux/bits/termios-baud.h with 51% similarity]
bits/termios.h
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/bits/termios.h
termios/Makefile

similarity index 51%
rename from sysdeps/unix/sysv/linux/bits/termios-baud.h
rename to bits/termios-baud.h
index 1e41338b573971c5b60250dd2b481fc7f6014687..bafde1a6505cb57d7c36f3834b2570cce4cc1d0e 100644 (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.
 
 # 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
index 398efa5ddd2f2d3544de345a16498b9b5ce92016..8f0b817dbf4ca3a7c179abf5c2324cc013589cbf 100644 (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.  */ \
index ebcf820403ff81faf9decc9b82112c7c13904a97..a14b8c1f61818640998ffdcd3626898577ea6a90 100644 (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 \
index 14de3fcb55077be300943bc6d1f6a0d3494258a3..20746a07275940136592998bacff4c7e16e0feb4 100644 (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
 
index 08075424cb8a25555c83dfcc9dd62436dc758d14..43235346f2dbaa323724cfdfc1b15c1a77b1ca29 100644 (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