Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / unistd / linux / isatty.cpp
blob205013897525b33d8496b998ca200f1b5f74d26b
1 //===-- Linux implementation of isatty ------------------------------------===//
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/unistd/isatty.h"
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
14 #include "src/errno/libc_errno.h"
15 #include <sys/ioctl.h> // For ioctl numbers.
16 #include <sys/syscall.h> // For syscall numbers.
18 namespace LIBC_NAMESPACE {
20 LLVM_LIBC_FUNCTION(int, isatty, (int fd)) {
21 constexpr int INIT_VAL = 0x1234abcd;
22 int line_d_val = INIT_VAL;
23 // This gets the line dicipline of the terminal. When called on something that
24 // isn't a terminal it doesn't change line_d_val and returns -1.
25 int result =
26 LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TIOCGETD, &line_d_val);
27 if (result == 0)
28 return 1;
30 libc_errno = -result;
31 return 0;
34 } // namespace LIBC_NAMESPACE