From fcc35ab8865bf059fe3c004058d0566a1b4f4f4f Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Wed, 20 Apr 2016 15:06:53 -0400 Subject: [PATCH] ndk_patches: ttyname(_r) works in Android 5.0+ --- ndk_patches/unistd.patch | 55 ---------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 ndk_patches/unistd.patch diff --git a/ndk_patches/unistd.patch b/ndk_patches/unistd.patch deleted file mode 100644 index dcadd347d..000000000 --- a/ndk_patches/unistd.patch +++ /dev/null @@ -1,55 +0,0 @@ -diff -u -r /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/unistd.h ./usr/include/unistd.h ---- /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/unistd.h 2012-08-21 07:23:12.000000000 +0200 -+++ ./usr/include/unistd.h 2014-07-09 09:55:58.443639544 +0200 -@@ -35,6 +35,7 @@ - #include - #include - #include -+#include - - __BEGIN_DECLS - -@@ -166,6 +174,43 @@ - extern char* ttyname(int); - extern int ttyname_r(int, char*, size_t); - -+/* start android polyfill of ttyname(3) and ttyname_r(3) */ -+#define ttyname(a) android_polyfill_ttyname(a) -+#define ttyname_r(a, b, c) android_polyfill_ttyname_r(a, b, c) -+ -+static int android_polyfill_ttyname_r(int fd, char* buf, size_t buflen) -+{ -+ char symlink_path[32] = "/proc/self/fd/"; -+ ssize_t siz; -+ -+ if (!isatty(fd)) return -1; -+ -+ /* Would like to do sprintf(symlink_path, "/proc/self/fd/%d", fd), but stdio.h may not be included. */ -+ int shifter = fd; -+ char* p = symlink_path + 14; -+ do { -+ p++; -+ shifter = shifter / 10; -+ } while(shifter); -+ *p = '\0'; -+ do { -+ *--p = (fd % 10) + '0'; -+ fd = fd / 10; -+ } while (fd); -+ -+ siz = readlink(symlink_path, buf, buflen); -+ if (siz < 0 || siz == buflen) return -1; -+ buf[siz] = '\0'; -+ return 0; -+} -+ -+static char* android_polyfill_ttyname(int fd) -+{ -+ static char buf[32]; -+ return (ttyname_r(fd, buf, sizeof(buf)) == 0) ? buf : NULL; -+} -+/* end android polyfill of ttyname(3) and ttyname_r(3) */ -+ - extern int acct(const char* filepath); - - static __inline__ int getpagesize(void) {