Commit | Line | Data |
---|---|---|
29bf3001 | 1 | diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/stdio.h ./usr/include/stdio.h |
392b4b6b FF |
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 | |
29bf3001 FF |
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 | + | |
392b4b6b | 11 | #include <bits/seek_constants.h> |
29bf3001 | 12 | |
392b4b6b FF |
13 | #if __ANDROID_API__ < __ANDROID_API_N__ |
14 | @@ -167,7 +170,7 @@ | |
29bf3001 | 15 | __warnattr_strict("vsprintf is often misused; please use vsnprintf"); |
392b4b6b | 16 | char* tmpnam(char* __s) |
29bf3001 FF |
17 | __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead"); |
18 | -#define P_tmpdir "/tmp/" /* deprecated */ | |
19 | +#define P_tmpdir "@TERMUX_PREFIX@/tmp/" /* deprecated */ | |
392b4b6b | 20 | char* tempnam(const char* __dir, const char* __prefix) |
29bf3001 FF |
21 | __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead"); |
22 | ||
392b4b6b FF |
23 | @@ -242,8 +245,6 @@ |
24 | FILE* freopen64(const char* __path, const char* __mode, FILE* __fp) __INTRODUCED_IN(24); | |
29bf3001 FF |
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 */ | |
392b4b6b | 32 | @@ -259,10 +260,15 @@ |
29bf3001 FF |
33 | |
34 | #define L_ctermid 1024 /* size for ctermid() */ | |
35 | ||
36 | -#if __ANDROID_API__ >= 26 | |
392b4b6b | 37 | -char* ctermid(char* __buf) __INTRODUCED_IN(26); |
29bf3001 | 38 | -#endif /* __ANDROID_API__ >= 26 */ |
392b4b6b | 39 | +/* Needed by gnulibs freading(). */ |
29bf3001 FF |
40 | +#define __sferror(p) (((p)->_flags & __SERR) != 0) |
41 | ||
392b4b6b | 42 | +/* Used by perl, fish, and others. */ |
29bf3001 | 43 | +static __inline__ char* ctermid(char* s) { |
392b4b6b FF |
44 | + if (s == 0) return (char*) "/dev/tty"; |
45 | + strcpy(s, "/dev/tty"); | |
46 | + return s; | |
29bf3001 FF |
47 | +} |
48 | ||
392b4b6b FF |
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 | |
29bf3001 | 54 | |
29bf3001 FF |
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(); | |
fd11c5fb | 66 | + if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL; |
29bf3001 FF |
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 | + | |
392b4b6b FF |
78 | __END_DECLS |
79 | ||
80 | #endif |