| 1 | #if defined(__ANDROID__) |
| 2 | #include <android/log.h> |
| 3 | |
| 4 | // Adapted from https://stackoverflow.com/a/196018/1904615 |
| 5 | #define V_ANDROID_LOG_STR_VALUE(arg) #arg |
| 6 | #define V_ANDROID_LOG_NAME(tag_name) V_ANDROID_LOG_STR_VALUE(tag_name) |
| 7 | |
| 8 | #ifndef V_ANDROID_LOG_TAG |
| 9 | #if defined(APPNAME) |
| 10 | #define V_ANDROID_LOG_TAG APPNAME |
| 11 | #else |
| 12 | #define V_ANDROID_LOG_TAG "V" |
| 13 | #endif |
| 14 | #endif |
| 15 | |
| 16 | #define V_ANDROID_LOG_TAG_NAME V_ANDROID_LOG_NAME(V_ANDROID_LOG_TAG) |
| 17 | |
| 18 | int android_print(FILE *stream, const char *format, ...) { |
| 19 | // int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap) |
| 20 | int res; |
| 21 | va_list argptr; |
| 22 | va_start(argptr, format); |
| 23 | if (stream == stdout) { |
| 24 | res = __android_log_vprint(ANDROID_LOG_INFO, V_ANDROID_LOG_TAG_NAME, format, argptr); |
| 25 | } else { |
| 26 | res = __android_log_vprint(ANDROID_LOG_ERROR, V_ANDROID_LOG_TAG_NAME, format, argptr); |
| 27 | } |
| 28 | return res; |
| 29 | } |
| 30 | #endif |
| 31 | |