chiark / gitweb /
Initial push
[termux-packages] / ndk_patches / unistd.patch
1 diff -u -r /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/unistd.h ./usr/include/unistd.h
2 --- /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/unistd.h   2012-08-21 07:23:12.000000000 +0200
3 +++ ./usr/include/unistd.h      2014-07-09 09:55:58.443639544 +0200
4 @@ -35,6 +35,7 @@
5  #include <sys/sysconf.h>
6  #include <linux/capability.h>
7  #include <pathconf.h>
8 +#include <asm/unistd.h>
9  
10  __BEGIN_DECLS
11  
12 @@ -166,6 +174,43 @@
13  extern char* ttyname(int);
14  extern int ttyname_r(int, char*, size_t);
15  
16 +/* start android polyfill of ttyname(3) and ttyname_r(3) */
17 +#define ttyname(a) android_polyfill_ttyname(a)
18 +#define ttyname_r(a, b, c) android_polyfill_ttyname_r(a, b, c)
19 +
20 +static int android_polyfill_ttyname_r(int fd, char* buf, size_t buflen)
21 +{
22 +       char symlink_path[32] = "/proc/self/fd/";
23 +       ssize_t siz;
24 +
25 +       if (!isatty(fd)) return -1;
26 +
27 +       /* Would like to do sprintf(symlink_path, "/proc/self/fd/%d", fd), but stdio.h may not be included. */
28 +       int shifter = fd;
29 +       char* p = symlink_path + 14;
30 +       do {
31 +               p++;
32 +               shifter = shifter / 10;
33 +       } while(shifter);
34 +       *p = '\0';
35 +       do {
36 +               *--p = (fd % 10) + '0';
37 +               fd = fd / 10;
38 +       } while (fd);
39 +
40 +       siz = readlink(symlink_path, buf, buflen);
41 +       if (siz < 0 || siz == buflen) return -1;
42 +       buf[siz] = '\0';
43 +       return 0;
44 +}
45 +
46 +static char* android_polyfill_ttyname(int fd)
47 +{
48 +       static char buf[32];
49 +       return (ttyname_r(fd, buf, sizeof(buf)) == 0) ? buf : NULL;
50 +}
51 +/* end android polyfill of ttyname(3) and ttyname_r(3) */
52 +
53  extern int  acct(const char*  filepath);
54  
55  static __inline__ int getpagesize(void) {