---
 include/platform.h    |  2 ++
 libbb/xfuncs_printf.c | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/platform.h b/include/platform.h
index 8914d4a..9893536 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -369,6 +369,7 @@ typedef unsigned smalluint;
 #define HAVE_MEMRCHR 1
 #define HAVE_MKDTEMP 1
 #define HAVE_PTSNAME_R 1
+#define HAVE_TTYNAME_R 1
 #define HAVE_SETBIT 1
 #define HAVE_SIGHANDLER_T 1
 #define HAVE_STPCPY 1
@@ -481,6 +482,7 @@ typedef unsigned smalluint;
 #if defined(ANDROID) || defined(__ANDROID__)
 # undef HAVE_DPRINTF
 # undef HAVE_GETLINE
+# undef HAVE_TTYNAME_R
 # undef HAVE_STPCPY
 # undef HAVE_MEMPCPY
 # undef HAVE_STRCHRNUL
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index e4ac6a0..bada57f 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -569,9 +569,19 @@ int FAST_FUNC bb_xioctl(int fd, unsigned request, void 
*argp)
 char* FAST_FUNC xmalloc_ttyname(int fd)
 {
        char buf[128];
+#ifdef HAVE_TTYNAME_R
        int r = ttyname_r(fd, buf, sizeof(buf) - 1);
        if (r)
                return NULL;
+#else
+       int r;
+       if (!isatty(fd))
+               return NULL;
+       sprintf(buf, "/proc/self/fd/%d", fd);
+       if ((r = readlink(buf, buf, sizeof(buf) - 1)) < 0)
+               return NULL;
+       buf[r] = '\0';
+#endif
        return xstrdup(buf);
 }
 
-- 
2.0.5

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to