[MLIR][TOSA] Update CustomOp input and output names (#118408)
[llvm-project.git] / libc / src / termios / linux / tcgetattr.cpp
blob63c096ff88eba1b1682d7e5c06c872bd2b0d4bd4
1 //===-- Linux implementation of tcgetattr ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/termios/tcgetattr.h"
10 #include "kernel_termios.h"
12 #include "src/__support/OSUtil/syscall.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
15 #include "src/errno/libc_errno.h"
17 #include <asm/ioctls.h> // Safe to include without the risk of name pollution.
18 #include <sys/syscall.h> // For syscall numbers
19 #include <termios.h>
21 namespace LIBC_NAMESPACE_DECL {
23 LLVM_LIBC_FUNCTION(int, tcgetattr, (int fd, struct termios *t)) {
24 LIBC_NAMESPACE::kernel_termios kt;
25 int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TCGETS, &kt);
26 if (ret < 0) {
27 libc_errno = -ret;
28 return -1;
30 t->c_iflag = kt.c_iflag;
31 t->c_oflag = kt.c_oflag;
32 t->c_cflag = kt.c_cflag;
33 t->c_lflag = kt.c_lflag;
34 t->c_ispeed = kt.c_cflag & CBAUD;
35 t->c_ospeed = kt.c_cflag & CBAUD;
37 size_t nccs = KERNEL_NCCS <= NCCS ? KERNEL_NCCS : NCCS;
38 for (size_t i = 0; i < nccs; ++i)
39 t->c_cc[i] = kt.c_cc[i];
40 if (NCCS > nccs) {
41 for (size_t i = nccs; i < NCCS; ++i)
42 t->c_cc[i] = 0;
44 return 0;
47 } // namespace LIBC_NAMESPACE_DECL