From ba9ce9c13b42b93c5725544aceb2786089862562 Mon Sep 17 00:00:00 2001 From: vaibhavg20comp Date: Tue, 7 Feb 2023 09:55:12 +0530 Subject: [PATCH] termios: Added cfsetspeed function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BSD extension to set both the input and output speed of a termios structure. Fixes #18220. Change-Id: I8c4a06b4be4aa55b8ce35cb7f62552fc47a8e8d0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6049 Reviewed-by: Jérôme Duval --- headers/compatibility/bsd/termios.h | 30 +++++++++++++++++++++++++++++ src/libs/bsd/Jamfile | 1 + src/libs/bsd/termios.c | 27 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 headers/compatibility/bsd/termios.h create mode 100644 src/libs/bsd/termios.c diff --git a/headers/compatibility/bsd/termios.h b/headers/compatibility/bsd/termios.h new file mode 100644 index 0000000000..a410989995 --- /dev/null +++ b/headers/compatibility/bsd/termios.h @@ -0,0 +1,30 @@ +/* + * Copyright 2023 Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _BSD_TERMIOS_H_ +#define _BSD_TERMIOS_H_ + + +#include_next +#include + + +#ifdef _DEFAULT_SOURCE + + +#ifdef __cplusplus +extern "C" { +#endif + +extern int cfsetspeed(struct termios *termios, speed_t speed); + +#ifdef __cplusplus +} +#endif + + +#endif + + +#endif /* _BSD_TERMIOS_H_ */ diff --git a/src/libs/bsd/Jamfile b/src/libs/bsd/Jamfile index 1d3c7d836e..c34154a01f 100644 --- a/src/libs/bsd/Jamfile +++ b/src/libs/bsd/Jamfile @@ -24,6 +24,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { signal.c string.cpp stringlist.c + termios.c unvis.c usershell.c vis.c diff --git a/src/libs/bsd/termios.c b/src/libs/bsd/termios.c new file mode 100644 index 0000000000..1049aeea6a --- /dev/null +++ b/src/libs/bsd/termios.c @@ -0,0 +1,27 @@ +/* + * Copyright 2023, Haiku, inc. + * + * Distributed under the terms of the MIT License. + */ + + +#include + + +int +cfsetspeed(struct termios *termios, speed_t speed) +{ + /* Custom speed values are stored in c_ispeed and c_ospeed. + * Standard values are inlined in c_cflag. */ + if (speed > B31250) { + termios->c_cflag |= CBAUD; + termios->c_ispeed = speed; + termios->c_ospeed = speed; + return 0; + } + + termios->c_cflag &= ~CBAUD; + termios->c_cflag |= speed; + return 0; +} +