~vorlon/ubuntu/natty/eglibc/multiarch

« back to all changes in this revision

Viewing changes to sysdeps/unix/sysv/linux/ttyname.c

  • Committer: Steve Langasek
  • Date: 2011-02-18 21:18:44 UTC
  • mfrom: (103.1.7 eglibc)
  • Revision ID: steve.langasek@linaro.org-20110218211844-lodmi8b1qhyq3f3x
Tags: 2.13~pre1-0ubuntu1+multiarch.1
merge from natty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1991,92,93,1996-2002,2006,2009 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1991-1993,1996-2002,2006,2009,2010
 
2
   Free Software Foundation, Inc.
2
3
   This file is part of the GNU C Library.
3
4
 
4
5
   The GNU C Library is free software; you can redistribute it and/or
131
132
  if (__builtin_expect (__tcgetattr (fd, &term) < 0, 0))
132
133
    return NULL;
133
134
 
 
135
  if (__fxstat64 (_STAT_VER, fd, &st) < 0)
 
136
    return NULL;
 
137
 
134
138
  /* We try using the /proc filesystem.  */
135
139
  *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
136
140
 
161
165
    {
162
166
      if ((size_t) len >= buflen)
163
167
        return NULL;
 
168
 
 
169
#define UNREACHABLE_LEN strlen ("(unreachable)")
 
170
      if (len > UNREACHABLE_LEN
 
171
          && memcmp (ttyname_buf, "(unreachable)", UNREACHABLE_LEN) == 0)
 
172
        {
 
173
          memmove (ttyname_buf, ttyname_buf + UNREACHABLE_LEN,
 
174
                   len - UNREACHABLE_LEN);
 
175
          len -= UNREACHABLE_LEN;
 
176
        }
 
177
 
164
178
      /* readlink need not terminate the string.  */
165
179
      ttyname_buf[len] = '\0';
166
 
      return ttyname_buf;
 
180
 
 
181
      /* Verify readlink result, fall back on iterating through devices.  */
 
182
      if (ttyname_buf[0] == '/'
 
183
          && __xstat64 (_STAT_VER, ttyname_buf, &st1) == 0
 
184
#ifdef _STATBUF_ST_RDEV
 
185
          && S_ISCHR (st1.st_mode)
 
186
          && st1.st_rdev == st.st_rdev
 
187
#else
 
188
          && st1.st_ino == st.st_ino
 
189
          && st1.st_dev == st.st_dev
 
190
#endif
 
191
          )
 
192
        return ttyname_buf;
167
193
    }
168
194
 
169
 
  if (__fxstat64 (_STAT_VER, fd, &st) < 0)
170
 
    return NULL;
171
 
 
172
195
  if (__xstat64 (_STAT_VER, "/dev/pts", &st1) == 0 && S_ISDIR (st1.st_mode))
173
196
    {
174
197
#ifdef _STATBUF_ST_RDEV