From dab9837091a70e6ed6ea0d6474e0508ea6fccde5 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 20 Sep 2002 20:18:24 +0000 Subject: * sysdeps/unix/bsd/bsd4.4/isatty.c: New file. * sysdeps/unix/bsd/isatty.c (__isatty): Don't save and restore errno. * sysdeps/unix/bsd/ptsname.c (__ptsname_r): Return errno value from isatty unmodified. Reported by Bruno Haible . --- sysdeps/unix/bsd/bsd4.4/isatty.c | 3 +++ sysdeps/unix/bsd/isatty.c | 11 ++--------- sysdeps/unix/bsd/ptsname.c | 12 +++++------- 3 files changed, 10 insertions(+), 16 deletions(-) create mode 100644 sysdeps/unix/bsd/bsd4.4/isatty.c (limited to 'sysdeps/unix/bsd') diff --git a/sysdeps/unix/bsd/bsd4.4/isatty.c b/sysdeps/unix/bsd/bsd4.4/isatty.c new file mode 100644 index 0000000000..473368c93f --- /dev/null +++ b/sysdeps/unix/bsd/bsd4.4/isatty.c @@ -0,0 +1,3 @@ +/* In a 4.4-derived world, tcgetattr is just one ioctl. */ + +#include diff --git a/sysdeps/unix/bsd/isatty.c b/sysdeps/unix/bsd/isatty.c index bd61ed62dc..996c4ed41f 100644 --- a/sysdeps/unix/bsd/isatty.c +++ b/sysdeps/unix/bsd/isatty.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1991,95,96,97,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 @@ -25,15 +25,8 @@ int __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; + return __ioctl (fd, TIOCGETP, &term) == 0; } - weak_alias (__isatty, isatty) diff --git a/sysdeps/unix/bsd/ptsname.c b/sysdeps/unix/bsd/ptsname.c index cd7c42fa33..fd446a4b66 100644 --- a/sysdeps/unix/bsd/ptsname.c +++ b/sysdeps/unix/bsd/ptsname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998 Free Software Foundation, Inc. +/* 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,22 +53,20 @@ __ptsname_r (int fd, char *buf, size_t buflen) } if (!__isatty (fd)) - { - __set_errno (ENOTTY); - return ENOTTY; - } + /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */ + return errno; if (buflen < strlen (_PATH_TTY) + 3) { __set_errno (ERANGE); return ERANGE; } - + if (__ttyname_r (fd, buf, buflen) != 0) return errno; buf[sizeof (_PATH_DEV) - 1] = 't'; - + if (__stat (buf, &st) < 0) return errno; -- cgit v1.2.3