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:
committed by
Denys Vlasenko
parent
de5edadee2
commit
cee59053dc
@@ -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
|
||||
|
Reference in New Issue
Block a user