[PATCH v2 4/5] termios: _SPEED_MAX and _BAUD_MAX constants

H. Peter Anvin hpa@zytor.com
Sun Jun 29 16:16:31 GMT 2025


Add constants indicating the maximum values of speed_t and baud_t.
Hopefully if and when the baud_t interface is standardized then
_BAUD_MAX will be included in the standardization from the start.

Historically, the __MAX_BAUD symbol has indicated the maximum speed_t
value on at least some platforms (including glibc).  However, this
name would be problematic for future standardization, because it
would imply a reference to baud_t, not speed_t, and it is inconsistent
with other limit symbols, which are all of the form *_MAX
(e.g. SIZE_MAX for size_t), but add an underscore to the front to
avoid stomping on the application namespace.

Furthermore, move __MAX_BAUD under __USE_MISC as it is not a
standardized symbol.

Signed-off-by: "H. Peter Anvin" (Intel) <hpa@zytor.com>
---
 bits/termios-baud.h | 5 ++++-
 termios/termios.h   | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/bits/termios-baud.h b/bits/termios-baud.h
index bafde1a6505c..b751a7d4064b 100644
--- a/bits/termios-baud.h
+++ b/bits/termios-baud.h
@@ -69,4 +69,7 @@
 #define B5000000       5000000U
 #define B10000000     10000000U
 
-#define __MAX_BAUD  4294967295U
+#ifdef __USE_MISC
+#define _SPEED_MAX  4294967295U	/* maximum valid speed_t value */
+#define __MAX_BAUD  _SPEED_MAX	/* legacy alias for _SPEED_MAX */
+#endif
diff --git a/termios/termios.h b/termios/termios.h
index 788c98240596..15ea29f95c82 100644
--- a/termios/termios.h
+++ b/termios/termios.h
@@ -62,6 +62,7 @@ extern int cfsetspeed (struct termios *__termios_p, speed_t __speed) __THROW;
 
 /* Interfaces that are explicitly numeric representations of baud rates */
 typedef speed_t baud_t;
+#define _BAUD_MAX _SPEED_MAX
 
 /* Return the output baud rate stored in *TERMIOS_P.  */
 extern baud_t cfgetobaud (const struct termios *__termios_p) __THROW;
-- 
2.50.0



More information about the Libc-alpha mailing list