summaryrefslogtreecommitdiff
path: root/libc/src/termios/linux/tcsendbreak.cpp
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2022-10-17 16:27:45 +0000
committerSiva Chandra Reddy <sivachandra@google.com>2022-10-18 20:53:00 +0000
commitb2a294bcf8e6fd83efe72d6d7432affd65b2309e (patch)
tree1e2615e3b9ffdc93118d45e699431ca006aa098e /libc/src/termios/linux/tcsendbreak.cpp
parentbcc4c909544e136ac7198d0acf6768817b702bed (diff)
[libc] Add termios.h and the implementation of functions declared in it.
Reviewed By: lntue, michaelrj Differential Revision: https://reviews.llvm.org/D136143
Diffstat (limited to 'libc/src/termios/linux/tcsendbreak.cpp')
-rw-r--r--libc/src/termios/linux/tcsendbreak.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/libc/src/termios/linux/tcsendbreak.cpp b/libc/src/termios/linux/tcsendbreak.cpp
new file mode 100644
index 000000000000..18aeba6b8098
--- /dev/null
+++ b/libc/src/termios/linux/tcsendbreak.cpp
@@ -0,0 +1,33 @@
+//===-- Linux implementation of tcsendbreak -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/termios/tcsendbreak.h"
+
+#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/common.h"
+
+#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
+#include <errno.h>
+#include <sys/syscall.h> // For syscall numbers
+#include <termios.h>
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(pid_t, tcsendbreak, (int fd, int /* unused duration */)) {
+ // POSIX leaves the behavior for non-zero duration implementation dependent.
+ // Which means that the behavior can be the same as it is when duration is
+ // zero. So, we just pass zero to the syscall.
+ long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 0);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+ return 0;
+}
+
+} // namespace __llvm_libc