if (__ioctl (fd, TIOCGPTN, &ptyno) == 0) goto gotit; else
char numbuf[21]; const char *devpts = _PATH_DEVPTS; const size_t devptslen = strlen (devpts); char *p;  numbuf[20] = '\0'; p = _itoa_word (ptyno, &numbuf[20], 10, 0);  if (buflen < devptslen + strlen (p) + 1)
__ptsname_r (fd, buf, buflen)     int fd;     char *buf;     size_t buflen;{  struct stat st;  int save = errno;  int ptyno;  char nbuf[PTYNAMELEN], idbuf[6];  char *cp;#ifdef TIOCGPTN  static int tiocgptn_works = 1;#endif  if (!buf)    {      __set_errno (EINVAL);      return EINVAL;    }  if (!__isatty (fd))    {      __set_errno (ENOTTY);      return ENOTTY;    }#ifdef TIOCGPTN  if (tiocgptn_works)    {      if (__ioctl (fd, TIOCGPTN, &ptyno) == 0)	goto gotit;      else	{	  if(errno != EINVAL)	    return errno;	  else	    tiocgptn_works = 0;	}    }#endif  if (__fxstat (_STAT_VER, fd, &st) < 0)    return errno;  ptyno = minor (st.st_rdev);  if (major (st.st_rdev) == 4)    ptyno -= 128;#ifdef TIOCGPTN gotit:#endif  /* Two different possible naming schemes for pty slaves:     the SVr4 way.  */  idbuf[5] = '\0';  __stpcpy (__stpcpy (nbuf, "/dev/pts/"),	    _itoa_word (ptyno, &idbuf[5], 10, 0));  if (__xstat (_STAT_VER, nbuf, &st) < 0)    {      if (errno != ENOENT)	return errno;      /* ...and the BSD way.  */      nbuf[5]  = 't';      nbuf[7]  = 'y';      nbuf[8]  = __ptyname1[ptyno / 16];      nbuf[9]  = __ptyname2[ptyno % 16];      nbuf[10] = '\0';      if (__xstat (_STAT_VER, nbuf, &st) < 0)	return errno;    }  if (buflen < strlen (nbuf) + 1)    {      __set_errno (ERANGE);      return ERANGE;    }  cp = __stpncpy (buf, nbuf, buflen);  cp[0] = '\0';  __set_errno (save);  return 0;}