1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

Fix getttyname on Linux when called for different devices.

If a second call to ttyname is not for the same type of device (e.g.,
serial vs ptty) the prefix of the buffer was wrong.  Don't rely on
the previous content, always reinitialize it.
This commit is contained in:
Ulrich Drepper
2009-10-29 11:02:34 -07:00
parent 8d55628106
commit d94760f944
2 changed files with 12 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991,92,93,1996-2002,2006 Free Software Foundation, Inc.
/* Copyright (C) 1991,92,93,1996-2002,2006,2009 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
@ -59,6 +59,11 @@ getttyname (const char *dev, dev_t mydev, ino64_t myino, int save, int *dostat)
return NULL;
}
/* Prepare for the loop. If we already have a buffer copy the directory
name we look at into it. */
if (devlen < namelen)
*((char *) __mempcpy (getttyname_name, dev, devlen - 1)) = '/';
while ((d = __readdir64 (dirstream)) != NULL)
if ((d->d_fileno == myino || *dostat)
&& strcmp (d->d_name, "stdin")