From c4929eecf7104f266f546ec742ca38ceee0e99c5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Wed, 11 Jun 2025 18:35:33 -0700 Subject: 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) Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/isatty_nostatus.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/isatty_nostatus.c (limited to 'sysdeps/unix/sysv') 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 + . */ + +#include +#include +#include +#include + +/* 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; +} -- cgit v1.1