aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/getlogin.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-04-28 15:00:14 -0700
committerRoland McGrath <roland@redhat.com>2010-04-28 15:00:14 -0700
commit8c0677fe5d91b7269364ca08fa08ed09e4c2d8c9 (patch)
treebf7c3ab332c3f5443cae34a82656765cb30c2a23 /sysdeps/unix/getlogin.c
parent6cffee3611f324326ae46bb02d2baeb62c0db6a4 (diff)
downloadglibc-8c0677fe5d91b7269364ca08fa08ed09e4c2d8c9.zip
glibc-8c0677fe5d91b7269364ca08fa08ed09e4c2d8c9.tar.gz
glibc-8c0677fe5d91b7269364ca08fa08ed09e4c2d8c9.tar.bz2
BZ #11538: Fix ttyname_r callers not to expect errno was set.
Diffstat (limited to 'sysdeps/unix/getlogin.c')
-rw-r--r--sysdeps/unix/getlogin.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sysdeps/unix/getlogin.c b/sysdeps/unix/getlogin.c
index b0ad97c..1fb7073 100644
--- a/sysdeps/unix/getlogin.c
+++ b/sysdeps/unix/getlogin.c
@@ -38,6 +38,7 @@ getlogin (void)
{
char tty_pathname[2 + 2 * NAME_MAX];
char *real_tty_path = tty_pathname;
+ int err;
char *result = NULL;
struct utmp *ut, line, buffer;
@@ -50,8 +51,12 @@ getlogin (void)
thing to do. Note that ttyname(open("/dev/tty")) on those
systems returns /dev/tty, so that is not a possible solution for
getlogin(). */
- if (__ttyname_r (0, real_tty_path, sizeof (tty_pathname)) != 0)
- return NULL;
+ err = __ttyname_r (0, real_tty_path, sizeof (tty_pathname));
+ if (err != 0)
+ {
+ __set_errno (err);
+ return NULL;
+ }
real_tty_path += 5; /* Remove "/dev/". */