Override fprintf(stderr) in android_debug.h
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
#ifndef __ANDROID_DEBUG_H__
|
||||
#define __ANDROID_DEBUG_H__
|
||||
|
||||
// Redirect printf() to Android log
|
||||
// Put this file into CFLAGS: "-include ../android_debug.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -46,4 +50,20 @@ namespace std
|
||||
|
||||
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "SDL-app", __VA_ARGS__)
|
||||
|
||||
// Override fprintf(stderr, ...) constructs
|
||||
static inline int __sdl_logged_fprintf(FILE *stream, const char *format, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
if( stream == stderr || stream == stdout )
|
||||
ret = __android_log_vprint(ANDROID_LOG_INFO, "SDL-app", format, args);
|
||||
else
|
||||
ret = vfprintf(stream, format, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define fprintf(...) __sdl_logged_fprintf(__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user