5 void __procfdname(char *, unsigned);
7 int ttyname_r(int fd, char *name, size_t size)
10 char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
13 if (!isatty(fd)) return ENOTTY;
15 __procfdname(procname, fd);
16 l = readlink(procname, name, size);
18 if (l < 0) return errno;
19 else if (l == size) return ERANGE;
23 if (stat(name, &st1) || fstat(fd, &st2))
25 if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)