summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2017-10-13 14:01:00 (GMT)
committerMathis Rosenhauer <rosenhauer@dkrz.de>2017-10-13 14:01:00 (GMT)
commit8a6aeb58e3b5ba215844bdca8da16650bff93265 (patch)
tree3aa1ffc779af92122aba8fab379151ce2b58f90b
parente3d026ae13d2ff0bf9237382e9046ecc9d06e867 (diff)
downloadlibaec-8a6aeb58e3b5ba215844bdca8da16650bff93265.zip
libaec-8a6aeb58e3b5ba215844bdca8da16650bff93265.tar.gz
libaec-8a6aeb58e3b5ba215844bdca8da16650bff93265.tar.bz2
windows: support snprintf for older MSVC
-rw-r--r--CMakeLists.txt7
-rw-r--r--cmake/config.h.in3
-rw-r--r--configure.ac2
-rw-r--r--tests/check_aec.h14
4 files changed, 25 insertions, 1 deletions
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 <config.h>
#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"