[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / unistd / linux / isatty.cpp
blobbd12b6dc5b0b67f8fe47f5130976838a608eafae
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 __llvm_libc {
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 = __llvm_libc::syscall_impl(SYS_ioctl, fd, TIOCGETD, &line_d_val);
26 if (result == 0)
27 return 1;
29 libc_errno = -result;
30 return 0;
33 } // namespace __llvm_libc