Files
termux-packages/ndk-patches/29/stdio.h.patch
termux-pacman-bot 3a57ea4179 Update repo
2025-11-28 22:38:17 +00:00

86 lines
2.8 KiB
Diff

diff -u -r /home/builder/lib/android-ndk-r28b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdio.h ./usr/include/stdio.h
--- /home/builder/lib/android-ndk-r28b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdio.h 2024-11-14 00:52:25.000000000 +0000
+++ ./usr/include/stdio.h 2025-05-09 18:52:59.008875200 +0000
@@ -44,6 +44,11 @@
#include <stdarg.h>
#include <stddef.h>
+#if !defined(__swift__)
+#include <string.h> /* For strcpy(3) used by ctermid() */
+#endif
+#include <asm/fcntl.h> /* For O_RDWR and other O_* constants */
+
#include <bits/seek_constants.h>
#if __ANDROID_API__ < 24
@@ -149,7 +154,7 @@
__printflike(2, 0) __warnattr_strict("vsprintf is often misused; please use vsnprintf");
char* _Nullable tmpnam(char* _Nullable __s)
__warnattr("tmpnam is unsafe, use mkstemp or tmpfile instead");
-#define P_tmpdir "/tmp/" /* deprecated */
+#define P_tmpdir "@TERMUX_PREFIX@/tmp/" /* deprecated */
char* _Nullable tempnam(const char* _Nullable __dir, const char* _Nullable __prefix)
__warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
@@ -276,8 +281,6 @@
FILE* _Nullable freopen64(const char* _Nullable __path, const char* _Nonnull __mode, FILE* _Nonnull __fp) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
-__nodiscard FILE* _Nullable tmpfile(void);
-
#if __BIONIC_AVAILABILITY_GUARD(24)
__nodiscard FILE* _Nullable tmpfile64(void) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
@@ -291,9 +294,17 @@
#define L_ctermid 1024 /* size for ctermid() */
-#if __BIONIC_AVAILABILITY_GUARD(26)
-char* _Nonnull ctermid(char* _Nullable __buf) __INTRODUCED_IN(26);
-#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
+/* Needed by gnulibs freading(). */
+#define __sferror(p) (((p)->_flags & __SERR) != 0)
+
+/* Used by perl, fish, and others. */
+#if !defined(__swift__)
+static __inline__ char* _Nonnull ctermid(char* _Nullable s) {
+ if (s == 0) return (char*) "/dev/tty";
+ strcpy(s, "/dev/tty");
+ return s;
+}
+#endif
__nodiscard FILE* _Nullable fdopen(int __fd, const char* _Nonnull __mode);
@@ -363,6 +374,30 @@
#include <bits/fortify/stdio.h>
#endif
+int open(const char*, int, ...);
+extern pid_t getpid();
+extern int unlink(const char*);
+void free(void* p);
+uint32_t arc4random(void);
+static __inline__ FILE* _Nullable tmpfile() {
+ int p = getpid();
+ char* path;
+ int i;
+ for (i = 0; i < 100; i++) {
+ unsigned int r = arc4random();
+ if (asprintf(&path, "@TERMUX_PREFIX@/tmp/tmpfile.%d-%u", p, r) == -1) return NULL;
+ int fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600);
+ if (fd >= 0) {
+ FILE* result = fdopen(fd, "w+");
+ unlink(path);
+ free(path);
+ return result;
+ }
+ free(path);
+ }
+ return NULL;
+}
+
__END_DECLS
#endif