b7cb7fc47b46495f2401ee3b1d0156a855523d67
[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 <fcntl.h> /* For O_RDWR and other O_* constants */
10 +#include <stdlib.h> /* For random() */
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 char* ctermid(char* s) {
41 + if (s == 0) return "/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,26 @@
50
51 #endif /* defined(__BIONIC_FORTIFY) */
52
53 +__BEGIN_DECLS
54 +
55 +static FILE* tmpfile() {
56 + int p = getpid();
57 + char* path;
58 + int i;
59 + for (i = 0; i < 100; i++) {
60 + long int r = random();
61 + if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%l", p, r) == -1) return NULL;
62 + int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE);
63 + free(path);
64 + if (fd >= 0) {
65 + FILE* result = fdopen(fd, "w+");
66 + unlink(path);
67 + return result;
68 + }
69 + }
70 + return NULL;
71 +}
72 +
73 +__END_DECLS
74 +
75 #endif /* _STDIO_H_ */