ndk-patches: Fix malformed <utmp.h> patch
[termux-packages] / ndk-patches / stdio.h.patch
1 diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h ./usr/include/stdio.h
2 --- /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h 2017-06-07 01:07:52.000000000 +0200
3 +++ ./usr/include/stdio.h 2017-06-18 01:59:17.835984565 +0200
4 @@ -44,6 +44,9 @@
5 #include <stdarg.h>
6 #include <stddef.h>
7
8 +#include <string.h> /* For strcpy(3) used by ctermid() */
9 +#include <asm/fcntl.h> /* For O_RDWR and other O_* constants */
10 +
11 #define __need_NULL
12 #include <stddef.h>
13
14 @@ -174,7 +178,7 @@
15 __warnattr_strict("vsprintf is often misused; please use vsnprintf");
16 char* tmpnam(char*)
17 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
18 -#define P_tmpdir "/tmp/" /* deprecated */
19 +#define P_tmpdir "@TERMUX_PREFIX@/tmp/" /* deprecated */
20 char* tempnam(const char*, const char*)
21 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
22
23 @@ -239,8 +243,6 @@
24 __INTRODUCED_IN(24);
25 #endif /* __ANDROID_API__ >= 24 */
26
27 -FILE* tmpfile(void);
28 -
29 #if __ANDROID_API__ >= 24
30 FILE* tmpfile64(void) __INTRODUCED_IN(24);
31 #endif /* __ANDROID_API__ >= 24 */
32 @@ -256,10 +258,15 @@
33
34 #define L_ctermid 1024 /* size for ctermid() */
35
36 -#if __ANDROID_API__ >= 26
37 -char* ctermid(char*) __INTRODUCED_IN(26);
38 -#endif /* __ANDROID_API__ >= 26 */
39 +/* Needed by gnulibs freading() */
40 +#define __sferror(p) (((p)->_flags & __SERR) != 0)
41
42 +/* Used by perl, fish, and others */
43 +static __inline__ char* ctermid(char* s) {
44 + if (s == 0) return (char*) "/dev/tty";
45 + strcpy(s, "/dev/tty");
46 + return s;
47 +}
48
49 FILE* fdopen(int, const char*);
50 int fileno(FILE*);
51 @@ -577,4 +584,31 @@
52
53 __END_DECLS
54
55 +__BEGIN_DECLS
56 +
57 +int open(const char*, int, ...) __overloadable __RENAME_CLANG(open);
58 +extern pid_t getpid();
59 +extern int unlink(const char*);
60 +void free(void* p);
61 +uint32_t arc4random(void);
62 +static __inline__ FILE* tmpfile() {
63 + int p = getpid();
64 + char* path;
65 + int i;
66 + for (i = 0; i < 100; i++) {
67 + unsigned int r = arc4random();
68 + if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL;
69 + int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600);
70 + free(path);
71 + if (fd >= 0) {
72 + FILE* result = fdopen(fd, "w+");
73 + unlink(path);
74 + return result;
75 + }
76 + }
77 + return NULL;
78 +}
79 +
80 +__END_DECLS
81 +
82 #endif /* _STDIO_H_ */