6 int ttyname_r(int fd
, char *name
, size_t size
)
9 char procname
[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
12 if (!isatty(fd
)) return errno
;
14 __procfdname(procname
, fd
);
15 l
= readlink(procname
, name
, size
);
17 if (l
< 0) return errno
;
18 else if (l
== size
) return ERANGE
;
22 if (stat(name
, &st1
) || fstat(fd
, &st2
))
24 if (st1
.st_dev
!= st2
.st_dev
|| st1
.st_ino
!= st2
.st_ino
)