Skip to content

Commit

Permalink
BZ #11538: Fix ttyname_r callers not to expect errno was set.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Haible authored and Roland McGrath committed Apr 28, 2010
1 parent 6cffee3 commit 8c0677f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
2010-04-25 Bruno Haible <bruno@clisp.org>

[BZ #11538]
* sysdeps/unix/bsd/ptsname.c (__ptsname_r): Use __ttyname_r's return
value instead of errno.
* sysdeps/unix/getlogin.c (getlogin): Likewise.

[BZ #11537]
* sysdeps/mach/hurd/ttyname_r.c (__ttyname_r): Upon failure, return
errno, not -1.
Expand Down
11 changes: 8 additions & 3 deletions sysdeps/unix/bsd/ptsname.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1998,2002 Free Software Foundation, Inc.
/* Copyright (C) 1998,2002,2010 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
Expand Down Expand Up @@ -44,6 +44,7 @@ int
__ptsname_r (int fd, char *buf, size_t buflen)
{
int save_errno = errno;
int err;
struct stat st;

if (buf == NULL)
Expand All @@ -62,8 +63,12 @@ __ptsname_r (int fd, char *buf, size_t buflen)
return ERANGE;
}

if (__ttyname_r (fd, buf, buflen) != 0)
return errno;
err = __ttyname_r (fd, buf, buflen);
if (err != 0)
{
__set_errno (err);
return errno;
}

buf[sizeof (_PATH_DEV) - 1] = 't';

Expand Down
9 changes: 7 additions & 2 deletions sysdeps/unix/getlogin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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/". */

Expand Down

0 comments on commit 8c0677f

Please sign in to comment.