ltrace: Fix incompatibilities with Android linker
[termux-packages] / ndk_patches / syslog.patch
1 diff -Nur /Users/fornwall/lib/android-ndk/platforms/android-18/arch-arm/usr/include/syslog.h ./usr/include/syslog.h
2 --- /Users/fornwall/lib/android-ndk/platforms/android-18/arch-arm/usr/include/syslog.h 2012-08-21 07:23:12.000000000 +0200
3 +++ ./usr/include/syslog.h 2014-01-29 17:51:55.000000000 +0100
4 @@ -31,6 +31,8 @@
5 #include <stdio.h>
6 #include <sys/cdefs.h>
7 #include <stdarg.h>
8 +#include <android/log.h> /* for __android_log_vprint() */
9 +#include <unistd.h> /* for getpid() */
10
11 __BEGIN_DECLS
12
13 @@ -111,6 +112,65 @@
14 extern void syslog_r(int, struct syslog_data *, const char *, ...);
15 extern void vsyslog_r(int, struct syslog_data *, const char *, va_list);
16
17 +extern /*const*/ char* __progname;
18 +static void android_polyfill_openlog(const char* a, int b, int c) {
19 + (void) a;
20 + (void) b;
21 + (void) c;
22 +}
23 +static void android_polyfill_closelog() {}
24 +
25 +static void android_polyfill_vsyslog(int syslog_priority, char const* format, va_list ap)
26 +{
27 + android_LogPriority a = ANDROID_LOG_FATAL;
28 + switch (syslog_priority) {
29 + case LOG_INFO : a = ANDROID_LOG_SILENT ; break;
30 + case LOG_EMERG : a = ANDROID_LOG_FATAL ; break;
31 + case LOG_ERR : a = ANDROID_LOG_ERROR ; break;
32 + case LOG_WARNING : a = ANDROID_LOG_WARN ; break;
33 + case LOG_DEBUG : a = ANDROID_LOG_VERBOSE ; break;
34 + }
35 + char* syslog_text;
36 + if (vasprintf(&syslog_text, format, ap) == -1) {
37 + __android_log_vprint(a, "syslog", format, ap);
38 + return;
39 + }
40 + __android_log_print(a, "syslog", "%s - %s", __progname, syslog_text);
41 + free(syslog_text);
42 +}
43 +
44 +static void android_polyfill_syslog(int priority, const char* format, ...)
45 +{
46 + va_list myargs;
47 + va_start(myargs, format);
48 + android_polyfill_vsyslog(priority, format, myargs);
49 + va_end(myargs);
50 +}
51 +
52 +static void android_polyfill_syslog_r(int syslog_priority, struct syslog_data* d, const char* format, ...)
53 +{
54 + (void) d;
55 + va_list myargs;
56 + va_start(myargs, format);
57 + android_polyfill_vsyslog(syslog_priority, format, myargs);
58 + va_end(myargs);
59 +}
60 +
61 +static void android_polyfill_vsyslog_r(int syslog_priority, struct syslog_data* d, const char* fmt, va_list ap)
62 +{
63 + (void) d;
64 + android_polyfill_vsyslog(syslog_priority, fmt, ap);
65 +}
66 +
67 +#define openlog android_polyfill_openlog
68 +#define closelog android_polyfill_closelog
69 +
70 +#define syslog android_polyfill_syslog
71 +#define syslog_r android_polyfill_syslog_r
72 +
73 +#define vsyslog android_polyfill_vsyslog
74 +#define vsyslog_r android_polyfill_vsyslog_r
75 +
76 __END_DECLS
77
78 #endif /* _SYSLOG_H */