if (__xstat (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode)) {
__ttyname_r (fd, buf, buflen)     int fd;     char *buf;     size_t buflen;{  static int dev_pts_available = 1;  char procname[30];  struct stat st, st1;  int dostat = 0;  int save = errno;  int ret;  /* Test for the absolute minimal size.  This makes life easier inside     the loop.  */  if (!buf)    {      __set_errno (EINVAL);      return EINVAL;    }  if (buflen < sizeof ("/dev/pts/"))    {      __set_errno (ERANGE);      return ERANGE;    }  if (!__isatty (fd))    {      __set_errno (ENOTTY);      return ENOTTY;    }  /* We try using the /proc filesystem.  */  *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';  ret = __readlink (procname, buf, buflen - 1);  if (ret != -1 && buf[0] != '[')    return 0;  if (ret == -1 && errno == ENAMETOOLONG)    {      __set_errno (ERANGE);      return ERANGE;    }  if (__fxstat (_STAT_VER, fd, &st) < 0)    return errno;  /* Prepare the result buffer.  */  memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/"));  buflen -= sizeof ("/dev/pts/") - 1;  if (dev_pts_available)    {      if (__xstat (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode))	{#ifdef _STATBUF_ST_RDEV	  ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,			      &dostat);#else	  ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,			      &dostat);#endif	}      else	{	  __set_errno (save);	  ret = ENOENT;	  dev_pts_available = 0;	}    }  if (ret && dostat != -1)    {      buf[sizeof ("/dev/") - 1] = '\0';      buflen += sizeof ("pts/") - 1;#ifdef _STATBUF_ST_RDEV      ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,			  &dostat);#else      ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,			  &dostat);#endif    }  if (ret && dostat != -1)    {      buf[sizeof ("/dev/") - 1] = '\0';      dostat = 1;#ifdef _STATBUF_ST_RDEV      ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino,			  save, &dostat);#else      ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino,			  save, &dostat);#endif    }  return ret;}