aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2025-06-11 18:35:33 -0700
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2025-06-17 09:11:38 -0300
commitc4929eecf7104f266f546ec742ca38ceee0e99c5 (patch)
tree8146dcc60b34449c7d95a4ca7b9c35c2b6e3d1ba /sysdeps/unix
parentedf7328db204f243c1bfde90edb11f99c7a13e14 (diff)
downloadglibc-c4929eecf7104f266f546ec742ca38ceee0e99c5.zip
glibc-c4929eecf7104f266f546ec742ca38ceee0e99c5.tar.gz
glibc-c4929eecf7104f266f546ec742ca38ceee0e99c5.tar.bz2
io: replace local_isatty() with a proper function __isatty_nostatus()
Replace local_isatty() inlined in libio with a proper function __isatty_nostatus(). This allows simpler system-specific implementations that don't need to touch errno at all. Note: I left the prototype in include/unistd.h (the internal header file.) It didn't much make sense to me to put it in a different header (not-cancel.h), but perhaps someone can elucidate the need. Add such an implementation for Linux, with a generic fallback. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/isatty_nostatus.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/isatty_nostatus.c b/sysdeps/unix/sysv/linux/isatty_nostatus.c
new file mode 100644
index 0000000..7f110be
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/isatty_nostatus.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1991-2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <termios.h>
+#include <kernel_termios.h>
+#include <sys/ioctl.h>
+
+/* Return 1 if FD is a terminal, 0 if not, without changing errno */
+int
+__isatty_nostatus (int fd)
+{
+ struct __kernel_termios k_termios;
+ return INTERNAL_SYSCALL_CALL (ioctl, fd, TCGETS, &k_termios) == 0;
+}