From 2f7dc59492a588a9b196c13a519fb5f2e42c274d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 18 Feb 2003 21:04:15 +0000 Subject: Update. 2003-02-18 Ulrich Drepper * sysdeps/unix/sysv/linux/ttyname_r.c (__ttyname_r): Recognize invalid file descriptors and missing access permissions. --- sysdeps/unix/sysv/linux/ttyname_r.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'sysdeps/unix') diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c index c23ded2..924b491 100644 --- a/sysdeps/unix/sysv/linux/ttyname_r.c +++ b/sysdeps/unix/sysv/linux/ttyname_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,92,93,1995-1999,2000,2001 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,93,1995-2001, 2003 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 @@ -115,26 +115,35 @@ __ttyname_r (int fd, char *buf, size_t buflen) return ERANGE; } + /* We try using the /proc filesystem. */ + *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0'; + + ret = __readlink (procname, buf, buflen - 1); + if (ret == -1 && errno == ENOENT) + { + __set_errno (EBADF); + return EBADF; + } + if (ret == -1 && errno == EACCES) + return EACCES; + if (!__isatty (fd)) { __set_errno (ENOTTY); return ENOTTY; } - /* We try using the /proc filesystem. */ - *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0'; + if (ret == -1 && errno == ENAMETOOLONG) + { + __set_errno (ERANGE); + return ERANGE; + } - ret = __readlink (procname, buf, buflen - 1); if (ret != -1 && buf[0] != '[') { buf[ret] = '\0'; return 0; } - if (ret == -1 && errno == ENAMETOOLONG) - { - __set_errno (ERANGE); - return ERANGE; - } if (__fxstat64 (_STAT_VER, fd, &st) < 0) return errno; -- cgit v1.1