aboutsummaryrefslogtreecommitdiff
path: root/libbb/platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/platform.c')
-rw-r--r--libbb/platform.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libbb/platform.c b/libbb/platform.c
index 8d90ca4e9..03bbb798b 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -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