dirstream = opendir (dev);
dirstream = __opendir (dev);
getttyname_r (fd, buf, buflen, mydev, myino, save, dostat)     int fd;     char *buf;     size_t buflen;     dev_t mydev;     ino_t myino;     int save;     int *dostat;{  struct stat st;  DIR *dirstream;  struct dirent *d;  dirstream = opendir (dev);  if (dirstream == NULL)    {      *dostat = -1;      return errno;    }  while ((d = readdir (dirstream)) != NULL)    if (((ino_t) d->d_fileno == myino || *dostat)	&& strcmp (d->d_name, "stdin")	&& strcmp (d->d_name, "stdout")	&& strcmp (d->d_name, "stderr"))      {	char *cp;	size_t needed = _D_EXACT_NAMLEN (d) + 1;	if (needed > buflen)	  {	    *dostat = -1;	    (void) closedir (dirstream);	    __set_errno (ERANGE);	    return ERANGE;	  }	cp = __stpncpy (&buf[sizeof (dev)], d->d_name, needed);	cp[0] = '\0';	if (stat (buf, &st) == 0#ifdef _STATBUF_ST_RDEV	    && S_ISCHR (st.st_mode) && st.st_rdev == mydev#else	    && (ino_t) d->d_fileno == myino && st.st_dev == mydev#endif	   )	  {	    (void) closedir (dirstream);	    __set_errno (save);	    return 0;	  }      }  (void) closedir (dirstream);  __set_errno (save);  /* It is not clear what to return in this case.  `isatty' says FD     refers to a TTY but no entry in /dev has this inode.  */  return ENOTTY;}