Bionic lacks ttyname_r; provide a workaround

Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Matt Whitlock
2015-04-25 21:32:48 +02:00
committed by Denys Vlasenko
parent de5edadee2
commit cee59053dc
2 changed files with 26 additions and 0 deletions

View File

@@ -194,3 +194,22 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream)
return len;
}
#endif
#ifndef HAVE_TTYNAME_R
int ttyname_r(int fd, char *buf, size_t buflen)
{
int r;
char path[sizeof("/proc/self/fd/%d") + sizeof(int)*3];
if (!isatty(fd))
return errno == EINVAL ? ENOTTY : errno;
sprintf(path, "/proc/self/fd/%d", fd);
r = readlink(path, buf, buflen);
if (r < 0)
return errno;
if (r >= buflen)
return ERANGE;
buf[r] = '\0';
return 0;
}
#endif