ndk_patches: ttyname(_r) works in Android 5.0+
authorFredrik Fornwall <fredrik@fornwall.net>
Wed, 20 Apr 2016 19:06:53 +0000 (15:06 -0400)
committerFredrik Fornwall <fredrik@fornwall.net>
Wed, 20 Apr 2016 19:06:53 +0000 (15:06 -0400)
ndk_patches/unistd.patch [deleted file]

diff --git a/ndk_patches/unistd.patch b/ndk_patches/unistd.patch
deleted file mode 100644 (file)
index dcadd34..0000000
+++ /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 <sys/sysconf.h>
- #include <linux/capability.h>
- #include <pathconf.h>
-+#include <asm/unistd.h>
- __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) {