diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-04-19 07:27:58 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-04-19 07:27:58 +0000 |
commit | f9d07577ce74d2f3da0e091940214ad16efbf3c0 (patch) | |
tree | 0c78aacfde5e00bb3ecdd04a8ee38ab3fad76f8d /sysdeps/unix/sysv/linux/ttyname.c | |
parent | 786dcb6287b61bbd5ebb905cbc5b1496b927d7b8 (diff) | |
download | glibc-f9d07577ce74d2f3da0e091940214ad16efbf3c0.tar.gz glibc-f9d07577ce74d2f3da0e091940214ad16efbf3c0.tar.xz glibc-f9d07577ce74d2f3da0e091940214ad16efbf3c0.zip |
* sysdeps/unix/sysv/linux/kernel-features.h: Define
__ASSUME_PROC_SELF_FD_SYMLINK. * sysdeps/unix/sysv/linux/ttyname.c: Cleanups. Avoid compatibility code is possible. Move compatibility code in .text.compat section. * sysdeps/unix/sysv/linux/ttyname_r.c: Likewise.
Diffstat (limited to 'sysdeps/unix/sysv/linux/ttyname.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/ttyname.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c index 68d24f195e..aed0fd8e0a 100644 --- a/sysdeps/unix/sysv/linux/ttyname.c +++ b/sysdeps/unix/sysv/linux/ttyname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,92,93,1996-2001,2002 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,93,1996-2002,2006 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 @@ -27,6 +27,7 @@ #include <stdlib.h> #include <stdio-common/_itoa.h> +#include <kernel-features.h> #if 0 /* Is this used anywhere? It is not exported. */ @@ -41,7 +42,7 @@ static char *getttyname (const char *dev, dev_t mydev, libc_freeres_ptr (static char *getttyname_name); static char * -internal_function +internal_function attribute_compat_text_section getttyname (const char *dev, dev_t mydev, ino64_t myino, int save, int *dostat) { static size_t namelen; @@ -117,10 +118,12 @@ ttyname (int fd) int dostat = 0; char *name; int save = errno; - int len; - if (!__isatty (fd)) - return NULL; + if (__builtin_expect (!__isatty (fd), 0)) + { + __set_errno (ENOTTY); + return NULL; + } /* We try using the /proc filesystem. */ *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0'; @@ -136,10 +139,19 @@ ttyname (int fd) } } - len = __readlink (procname, ttyname_buf, buflen); - if (len != -1 - /* This is for Linux 2.0. */ - && ttyname_buf[0] != '[') + ssize_t len = __readlink (procname, ttyname_buf, buflen); + if (__builtin_expect (len == -1 && errno == ENOENT, 0)) + { + __set_errno (EBADF); + return NULL; + } + + if (__builtin_expect (len != -1 +#ifndef __ASSUME_PROC_SELF_FD_SYMLINK + /* This is for Linux 2.0. */ + && ttyname_buf[0] != '[' +#endif + , 1)) { if ((size_t) len >= buflen) return NULL; |