From 8a6aeb58e3b5ba215844bdca8da16650bff93265 Mon Sep 17 00:00:00 2001 From: Mathis Rosenhauer Date: Fri, 13 Oct 2017 16:01:00 +0200 Subject: windows: support snprintf for older MSVC --- CMakeLists.txt | 7 +++++++ cmake/config.h.in | 3 +++ configure.ac | 2 +- tests/check_aec.h | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f24e0..1bcbdcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ set(CMAKE_C_STANDARD 99) include(CheckIncludeFiles) include(TestBigEndian) include(CheckCSourceCompiles) +include(CheckSymbolExists) include(cmake/macros.cmake) project(libaec) set(libaec_VERSION_MAJOR 1) @@ -21,6 +22,12 @@ endif(NOT HAVE_DECL___BUILTIN_CLZLL) find_inline_keyword() find_restrict_keyword() +check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) +if(NOT HAVE_SNPRINTF) + check_symbol_exists(_snprintf "stdio.h" HAVE__SNPRINTF) + check_symbol_exists(_snprintf_s "stdio.h" HAVE__SNPRINTF_S) +endif(NOT HAVE_SNPRINTF) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/cmake/config.h.in b/cmake/config.h.in index 9f5fffb..d5783e0 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -3,3 +3,6 @@ #cmakedefine WORDS_BIGENDIAN 1 #cmakedefine HAVE_DECL___BUILTIN_CLZLL 1 #cmakedefine HAVE_BSR64 1 +#cmakedefine HAVE_SNPRINTF 1 +#cmakedefine HAVE__SNPRINTF 1 +#cmakedefine HAVE__SNPRINTF_S 1 diff --git a/configure.ac b/configure.ac index 0226e03..d4789b9 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ AC_TYPE_UINT8_T AC_C_INLINE AC_C_RESTRICT -AC_CHECK_FUNCS([memset strstr]) +AC_CHECK_FUNCS([memset strstr snprintf]) AC_CHECK_DECLS(__builtin_clzll) AM_EXTRA_RECURSIVE_TARGETS([bench benc bdec]) diff --git a/tests/check_aec.h b/tests/check_aec.h index 02c3e77..2f6abd3 100644 --- a/tests/check_aec.h +++ b/tests/check_aec.h @@ -1,5 +1,7 @@ #ifndef CHECK_AEC_H #define CHECK_AEC_H 1 + +#include #include "libaec.h" struct test_state { @@ -24,6 +26,18 @@ int update_state(struct test_state *state); int encode_decode_small(struct test_state *state); int encode_decode_large(struct test_state *state); +#ifndef HAVE_SNPRINTF +#ifdef HAVE__SNPRINTF_S +#define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__) +#else +#ifdef HAVE__SNPRINTF +#define snprintf _snprintf +#else +#error "no snprintf compatible function found" +#endif /* HAVE__SNPRINTF */ +#endif /* HAVE__SNPRINTF_S */ +#endif /* HAVE_SNPRINTF */ + #ifdef _WIN32 #define CHECK_PASS "PASS" #define CHECK_FAIL "FAIL" -- cgit v1.2.3