Fix compilation for android

This commit is contained in:
Jeremy Lakeman 2012-07-11 16:04:21 +09:30
parent 38a5717789
commit 51d66f5d9e

8
log.c
View File

@ -86,8 +86,9 @@ void logMessage(int level, const char *file, unsigned int line, const char *func
void vlogMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, va_list ap) void vlogMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, va_list ap)
{ {
if (level != LOG_LEVEL_SILENT) { if (level != LOG_LEVEL_SILENT) {
if (strbuf_is_empty(&logbuf))
strbuf_init(&logbuf, _log_buf, sizeof _log_buf);
#ifndef ANDROID #ifndef ANDROID
FILE *logf = open_logging();
const char *levelstr = "UNKWN:"; const char *levelstr = "UNKWN:";
switch (level) { switch (level) {
case LOG_LEVEL_FATAL: levelstr = "FATAL:"; break; case LOG_LEVEL_FATAL: levelstr = "FATAL:"; break;
@ -96,10 +97,8 @@ void vlogMessage(int level, const char *file, unsigned int line, const char *fun
case LOG_LEVEL_WARN: levelstr = "WARN:"; break; case LOG_LEVEL_WARN: levelstr = "WARN:"; break;
case LOG_LEVEL_DEBUG: levelstr = "DEBUG:"; break; case LOG_LEVEL_DEBUG: levelstr = "DEBUG:"; break;
} }
#endif
if (strbuf_is_empty(&logbuf))
strbuf_init(&logbuf, _log_buf, sizeof _log_buf);
strbuf_sprintf(&logbuf, "%-6s ", levelstr); strbuf_sprintf(&logbuf, "%-6s ", levelstr);
#endif
if (log_pid) if (log_pid)
strbuf_sprintf(&logbuf, "[%5u] ", getpid()); strbuf_sprintf(&logbuf, "[%5u] ", getpid());
if (log_time) { if (log_time) {
@ -130,6 +129,7 @@ void vlogMessage(int level, const char *file, unsigned int line, const char *fun
__android_log_print(alevel, "servald", "%s", strbuf_str(&logbuf)); __android_log_print(alevel, "servald", "%s", strbuf_str(&logbuf));
strbuf_reset(&logbuf); strbuf_reset(&logbuf);
#else #else
FILE *logf = open_logging();
if (logf) { if (logf) {
fputs(strbuf_str(&logbuf), logf); fputs(strbuf_str(&logbuf), logf);
if (strbuf_overrun(&logbuf)) if (strbuf_overrun(&logbuf))