packages/libadns/: Various minor fixes.
[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-11-09 09:57:12.000000000 +0100
3 +++ ./usr/include/stdio.h 2017-11-15 11:57:58.567432093 +0100
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 #include <bits/seek_constants.h>
12
13 #if __ANDROID_API__ < __ANDROID_API_N__
14 @@ -167,7 +170,7 @@
15 __warnattr_strict("vsprintf is often misused; please use vsnprintf");
16 char* tmpnam(char* __s)
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* __dir, const char* __prefix)
21 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
22
23 @@ -242,8 +245,6 @@
24 FILE* freopen64(const char* __path, const char* __mode, FILE* __fp) __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 @@ -259,10 +260,15 @@
33
34 #define L_ctermid 1024 /* size for ctermid() */
35
36 -#if __ANDROID_API__ >= 26
37 -char* ctermid(char* __buf) __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 __fd, const char* __mode);
50 int fileno(FILE* __fp);
51 @@ -310,6 +316,29 @@
52 #include <bits/fortify/stdio.h>
53 #endif
54
55 +int open(const char*, int, ...) __overloadable __RENAME_CLANG(open);
56 +extern pid_t getpid();
57 +extern int unlink(const char*);
58 +void free(void* p);
59 +uint32_t arc4random(void);
60 +static __inline__ FILE* tmpfile() {
61 + int p = getpid();
62 + char* path;
63 + int i;
64 + for (i = 0; i < 100; i++) {
65 + unsigned int r = arc4random();
66 + if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL;
67 + int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600);
68 + free(path);
69 + if (fd >= 0) {
70 + FILE* result = fdopen(fd, "w+");
71 + unlink(path);
72 + return result;
73 + }
74 + }
75 + return NULL;
76 +}
77 +
78 __END_DECLS
79
80 #endif