about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/ttyname.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-10-29 11:02:34 -0700
committerUlrich Drepper <drepper@redhat.com>2009-10-29 11:02:34 -0700
commitd94760f944cebf05b239dd0b65c3b40a5577013b (patch)
tree8fc13b428f505fc948b55cc9bc92ea711d58f9a2 /sysdeps/unix/sysv/linux/ttyname.c
parent8d55628106730c5e318fa3673b69588509d983f2 (diff)
downloadglibc-d94760f944cebf05b239dd0b65c3b40a5577013b.tar.gz
glibc-d94760f944cebf05b239dd0b65c3b40a5577013b.tar.xz
glibc-d94760f944cebf05b239dd0b65c3b40a5577013b.zip
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.
Diffstat (limited to 'sysdeps/unix/sysv/linux/ttyname.c')
-rw-r--r--sysdeps/unix/sysv/linux/ttyname.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c
index 1b79787515..69af6adc65 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-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")