This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: FreeBSD port (42): ptsname
> Though POSIX.1 does not specify it, I think we want all GNU libc
> implementations of isatty to set errno in the canonical way,
> i.e. to either EBADF or ENOTTY.
OK, here is a patch to that effect.
> I don't see a reason to change the callers.
Still the caller (ptsname) needs a patch so that it doesn't convert
the correct errno from __isatty to an incorrect one (EBADF to ENOTTY).
2002-09-18 Bruno Haible <bruno@clisp.org>
* sysdeps/unix/bsd/isatty.c (__isatty): Set errno when returning 0.
* sysdeps/unix/bsd/ptsname.c (__ptsname_r): When isatty fails, don't
assume it was because of ENOTTY. It can also be EBADF.
diff -r -c3 glibc-20020910.bak/sysdeps/unix/bsd/isatty.c glibc-20020910/sysdeps/unix/bsd/isatty.c
*** glibc-20020910.bak/sysdeps/unix/bsd/isatty.c Tue Jul 10 23:01:20 2001
--- glibc-20020910/sysdeps/unix/bsd/isatty.c Wed Sep 18 02:43:25 2002
***************
*** 1,4 ****
! /* Copyright (C) 1991, 1995, 1996, 1997 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
--- 1,4 ----
! /* Copyright (C) 1991, 1995-1997, 2002 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
***************
*** 17,22 ****
--- 17,23 ----
02111-1307 USA. */
#include <errno.h>
+ #include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
***************
*** 25,37 ****
__isatty (fd)
int fd;
{
! int save;
int is_tty;
struct sgttyb term;
! save = errno;
is_tty = __ioctl (fd, TIOCGETP, &term) == 0;
! __set_errno (save);
return is_tty;
}
--- 26,50 ----
__isatty (fd)
int fd;
{
! int saved_errno;
int is_tty;
struct sgttyb term;
! saved_errno = errno;
is_tty = __ioctl (fd, TIOCGETP, &term) == 0;
! /* Note about errno: Although POSIX.1 specifies that isatty() may, but
! does not need to, set errno when it returns 0, we set errno in this
! case, for consistency with other platforms supported by GNU libc:
! EBADF if fd is invalid, ENOTTY if fd does not refer to a tty. */
! if (is_tty)
! __set_errno (saved_errno);
! else
! {
! if (__fcntl (fd, F_GETFD, 0) < 0)
! __set_errno (EBADF);
! else
! __set_errno (ENOTTY);
! }
return is_tty;
}
diff -r -c3 glibc-20020910.bak/sysdeps/unix/bsd/ptsname.c glibc-20020910/sysdeps/unix/bsd/ptsname.c
*** glibc-20020910.bak/sysdeps/unix/bsd/ptsname.c Tue Jul 10 23:01:20 2001
--- glibc-20020910/sysdeps/unix/bsd/ptsname.c Wed Sep 18 23:40:05 2002
***************
*** 1,4 ****
! /* Copyright (C) 1998 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
--- 1,4 ----
! /* Copyright (C) 1998, 2002 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
***************
*** 53,62 ****
}
if (!__isatty (fd))
! {
! __set_errno (ENOTTY);
! return ENOTTY;
! }
if (buflen < strlen (_PATH_TTY) + 3)
{
--- 53,60 ----
}
if (!__isatty (fd))
! /* After __isatty() failed, errno is usually either EBADF or ENOTTY. */
! return errno;
if (buflen < strlen (_PATH_TTY) + 3)
{