[PATCH 1/2] Bionic lacks ttyname_r; provide a workaround

Matt Whitlock busybox at mattwhitlock.name
Fri Apr 24 19:32:33 UTC 2015


---
 libbb/missing_syscalls.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
index dd430e3..e57c2de 100644
--- a/libbb/missing_syscalls.c
+++ b/libbb/missing_syscalls.c
@@ -39,4 +39,18 @@ int pivot_root(const char *new_root, const char *put_old)
 {
 	return syscall(__NR_pivot_root, new_root, put_old);
 }
+
+int ttyname_r(int fd, char *buf, size_t buflen) {
+	int r;
+	char path[32];
+	if (!isatty(fd))
+		return errno == EINVAL ? ENOTTY : errno;
+	sprintf(path, "/proc/self/fd/%d", fd);
+	if ((r = readlink(path, buf, buflen)) < 0)
+		return errno;
+	if (r >= buflen)
+		return ERANGE;
+	buf[r] = '\0';
+	return 0;
+}
 #endif
-- 
2.0.5



More information about the busybox mailing list