[PATCH RFC v3 2/8] io: make __local_isatty () a function; stub should return 0

H. Peter Anvin hpa@zytor.com
Mon May 12 18:04:34 GMT 2025


On 5/8/25 10:39, Adhemerval Zanella Netto wrote:
>>
>> diff --git a/include/unistd.h b/include/unistd.h
>> index e241603b8131..18d56bc4ee0d 100644
>> --- a/include/unistd.h
>> +++ b/include/unistd.h
>> @@ -152,6 +152,7 @@ libc_hidden_proto (__ttyname_r)
>>   extern __pid_t _Fork (void);
>>   libc_hidden_proto (_Fork);
>>   extern int __isatty (int __fd) attribute_hidden;
>> +extern int __local_isatty (int __fd) attribute_hidden;
> 
> For other internal implementation that do not set errno, usually they
> are name as __symbol_nocancel (like the ones in not-cancel.h).
> 

Wouldn't that imply additional properties? Specifically, what would be 
required to prevent a cancellation point from existing there? And should 
there be?

> 
> The idea of stub implementation is to future pots, although it is unlikely
> we will see any in the future.  So ENOSYS is to advertise that if you deploy
> glibc and programs are calling isatty, you will need to proper implement it
> instead of handling a ENOTTY.
> 
> So I think this change is not required.

OK. I guess it would make sense to, if the need ever comes up, have an 
explicit opt-in for a no-tty platform (which perhaps should inline 
isatty() et al) and not trigger a stub warning.

>> diff --git a/sysdeps/unix/sysv/linux/local_isatty.c b/sysdeps/unix/sysv/linux/local_isatty.c
>> new file mode 100644
>> index 000000000000..3bd5f67ea7da
>> --- /dev/null
>> +++ b/sysdeps/unix/sysv/linux/local_isatty.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
>> +__local_isatty (int fd)
>> +{
>> +  struct __kernel_termios k_termios;
>> +  return INTERNAL_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios) == 0;
> 
> Use INTERNAL_SYSCALL_CALL macro here, to avoid the need to pass the
> number of arguments.
> 

OK. Also see previous question :)

	-hpa



More information about the Libc-alpha mailing list