diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index 81fb023..50fff78 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -46,7 +46,12 @@ SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) IF(LIBNFC_LOG) - LIST(APPEND LIBRARY_SOURCES log-printf) + IF(WIN32) + SET(CMAKE_C_FLAGS "-fgnu89-inline ${CMAKE_C_FLAGS}") + LIST(APPEND LIBRARY_SOURCES log-printf log_win32) + ELSE(WIN32) + LIST(APPEND LIBRARY_SOURCES log-printf log_posix) + ENDIF(WIN32) ENDIF(LIBNFC_LOG) ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES}) diff --git a/libnfc/Makefile.am b/libnfc/Makefile.am index 7fc31ed..c6098a6 100644 --- a/libnfc/Makefile.am +++ b/libnfc/Makefile.am @@ -45,5 +45,7 @@ endif EXTRA_DIST = \ CMakeLists.txt \ - log-printf.c + log-printf.c \ + log_posix.c \ + log_win32.c diff --git a/libnfc/log-printf.c b/libnfc/log-printf.c index e8ef238..a0c1513 100644 --- a/libnfc/log-printf.c +++ b/libnfc/log-printf.c @@ -1,6 +1,7 @@ /*- * Copyright (C) 2011 Romain Tartière * Copyright (C) 2011, 2012 Romuald Conty + * Copyright (C) 2013 Alex Lian * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the @@ -31,6 +32,12 @@ #error "No logging defined, but log-printf.c still compiled." #else // LOG +// Internal methods so different platforms can route the logging +// Offering both forms of the variadic function +// These are implemented in the log_ specific file +void log_put_internal(const char *format, ...); +void log_vput_internal(const char *format, va_list args); + void log_init(const nfc_context *context) { @@ -71,11 +78,17 @@ log_put(const uint8_t group, const char *category, const uint8_t priority, const if (log_level) { // If log is not disabled by log_level=none if (((log_level & 0x00000003) >= priority) || // Global log level (((log_level >> (group * 2)) & 0x00000003) >= priority)) { // Group log level + va_list va; va_start(va, format); - fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category); - vfprintf(stderr, format, va); - fprintf(stderr, "\n"); + +// fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category); +// vfprintf(stderr, format, va); +// fprintf(stderr, "\n"); + + log_put_internal("%s\t%s\t", log_priority_to_str(priority), category); + log_vput_internal(format, va); + log_put_internal("\n"); va_end(va); } } diff --git a/libnfc/log_posix.c b/libnfc/log_posix.c new file mode 100644 index 0000000..3e963d2 --- /dev/null +++ b/libnfc/log_posix.c @@ -0,0 +1,41 @@ +/*- + * Copyright (C) 2011 Romain Tartière + * Copyright (C) 2011, 2012 Romuald Conty + * Copyright (C) 2013 Alex Lian + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + */ + +#include "log.h" + +#include +#include +#include +#include +#include + +void +log_vput_internal(const char *format, va_list args) +{ + vfprintf(stderr, format, args); +} + +void +log_put_internal(const char *format, ...) +{ + va_list va; + va_start(va, format); + vfprintf(stderr, format, va); + va_end(va); +} diff --git a/libnfc/log_win32.c b/libnfc/log_win32.c new file mode 100644 index 0000000..3713cfb --- /dev/null +++ b/libnfc/log_win32.c @@ -0,0 +1,56 @@ +/*- + * Copyright (C) 2011 Romain Tartière + * Copyright (C) 2011, 2012 Romuald Conty + * Copyright (C) 2013 Alex Lian + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + */ + +#include "log.h" + +#include +#include +#include +#include +#include +#include + +void +log_output_debug(const char *format, va_list args) +{ + char buffer[1024]; + HRESULT hr = StringCbVPrintf( buffer, sizeof( buffer ), format, args ); + // Spew what we got, even if the buffer is not sized large enough + if ( (STRSAFE_E_INSUFFICIENT_BUFFER == hr) || (S_OK == hr) ) + OutputDebugString( buffer ); +} + +void +log_vput_internal(const char *format, va_list args) +{ + vfprintf(stderr, format, args); + // Additional windows output to the debug window for debugging purposes + log_output_debug(format, args); +} + +void +log_put_internal(const char *format, ...) +{ + va_list va; + va_start(va, format); + vfprintf(stderr, format, va); + // Additional windows output to the debug window for debugging purposes + log_output_debug(format, va); + va_end(va); +}