serf: Fix building with unified headers
[termux-packages] / ndk_patches / stdio.h.patch
1 diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/stdio.h ./usr/include/stdio.h
2 --- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/stdio.h 2016-03-03 16:54:24.000000000 -0500
3 +++ ./usr/include/stdio.h 2016-04-11 06:54:22.893930847 -0400
4 @@ -52,6 +52,10 @@
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 +#include <stdlib.h> /* For arc4random() */
11 +
12 #define __need_NULL
13 #include <stddef.h>
14
15 @@ -193,7 +196,7 @@
16
17 /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
18 #if __BSD_VISIBLE || __XPG_VISIBLE
19 -#define P_tmpdir "/tmp/"
20 +#define P_tmpdir "@TERMUX_PREFIX@/tmp/"
21 #endif
22 #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
23 #define TMP_MAX 308915776
24 @@ -257,7 +260,6 @@
25 int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
26 int sscanf(const char * __restrict, const char * __restrict, ...)
27 __scanflike(2, 3);
28 -FILE *tmpfile(void);
29 int ungetc(int, FILE *);
30 int vfprintf(FILE * __restrict, const char * __restrict, __va_list)
31 __printflike(2, 0);
32 @@ -371,6 +373,16 @@
33 #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
34 #endif /* __BSD_VISIBLE */
35
36 +/* Needed by gnulibs freading() */
37 +#define __sferror(p) (((p)->_flags & __SERR) != 0)
38 +
39 +/* Used by perl, fish, and others */
40 +static __inline__ char* ctermid(char* s) {
41 + if (s == 0) return (char*) "/dev/tty";
42 + strcpy(s, "/dev/tty");
43 + return s;
44 +}
45 +
46 #if defined(__BIONIC_FORTIFY)
47
48 __BEGIN_DECLS
49 @@ -462,4 +474,29 @@
50
51 #endif /* defined(__BIONIC_FORTIFY) */
52
53 +__BEGIN_DECLS
54 +
55 +extern int open(const char*, int, ...);
56 +extern pid_t getpid();
57 +extern int unlink(const char*);
58 +static __inline__ FILE* tmpfile() {
59 + int p = getpid();
60 + char* path;
61 + int i;
62 + for (i = 0; i < 100; i++) {
63 + unsigned int r = arc4random();
64 + if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL;
65 + int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600);
66 + free(path);
67 + if (fd >= 0) {
68 + FILE* result = fdopen(fd, "w+");
69 + unlink(path);
70 + return result;
71 + }
72 + }
73 + return NULL;
74 +}
75 +
76 +__END_DECLS
77 +
78 #endif /* _STDIO_H_ */