diff --git a/.travis.yml b/.travis.yml index 2aa2eef..df2014d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,16 +16,17 @@ os: before_install: - echo $LANG - echo $LC_ALL + - set -e install: - sh autogen.sh before_script: - - ./configure + - ./configure --enable-strerror-override script: - make after_success: - make check - - cppcheck --quiet *.h *.c tests/ + - if type cppcheck &> /dev/null ; then cppcheck --error-exitcode=1 --quiet *.h *.c tests/ ; fi diff --git a/Makefile.am b/Makefile.am index 126ceeb..6f86525 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,12 @@ libjson_c_la_SOURCES = \ printbuf.c \ random_seed.c +if ENABLE_STRERROR_OVERRIDE +libjson_cinclude_HEADERS+= \ + strerror_override.h +libjson_c_la_SOURCES+= \ + strerror_override.c +endif distclean-local: -rm -rf $(testsubdir) diff --git a/configure.ac b/configure.ac index 3a2779e..7af60bf 100644 --- a/configure.ac +++ b/configure.ac @@ -7,6 +7,8 @@ AM_INIT_AUTOMAKE AC_PROG_MAKE_SET +AC_CANONICAL_HOST + AC_ARG_ENABLE(rdrand, AS_HELP_STRING([--enable-rdrand], [Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]), @@ -21,6 +23,22 @@ else AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable]) fi +AC_ARG_ENABLE(strerror-override, + AS_HELP_STRING([--enable-strerror-override], + [Override strerror() function with internal version.]), +[if test x$enableval = xyes; then + enable_strerror_override=yes + AC_DEFINE(ENABLE_STRERROR_OVERRIDE, 1, [Override strerror() with internal version]) +fi]) + +AM_CONDITIONAL([ENABLE_STRERROR_OVERRIDE], [test "x$enable_strerror_override" = "xyes"]) + +if test "x$enable_strerror_override" = "xyes"; then + AC_MSG_RESULT([Overriding `strerror()` function with internal version]) +else + AC_MSG_RESULT([Using libc's `strerror()` function]) +fi + # enable silent build by default m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) @@ -57,7 +75,7 @@ AS_IF([test "x$ac_cv___thread" != xno], AC_FUNC_VPRINTF AC_FUNC_MEMCMP AC_CHECK_FUNCS([realloc]) -AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale uselocale) +AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale) AC_CHECK_DECLS([INFINITY], [], [], [[#include ]]) AC_CHECK_DECLS([nan], [], [], [[#include ]]) AC_CHECK_DECLS([isnan], [], [], [[#include ]]) @@ -65,6 +83,14 @@ AC_CHECK_DECLS([isinf], [], [], [[#include ]]) AC_CHECK_DECLS([_isnan], [], [], [[#include ]]) AC_CHECK_DECLS([_finite], [], [], [[#include ]]) +case "${host_os}" in + linux*) + AC_CHECK_FUNCS([uselocale]) + ;; + *) # Nothing + ;; +esac + if test "$ac_cv_have_decl_isnan" = "yes" ; then AC_TRY_LINK([#include ], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"]) fi diff --git a/json_object.c b/json_object.c index ddc96bc..8c80426 100644 --- a/json_object.c +++ b/json_object.c @@ -12,13 +12,14 @@ #include "config.h" +#include "strerror_override.h" + #include #include #include #include #include #include -#include #include "debug.h" #include "printbuf.h" diff --git a/json_pointer.c b/json_pointer.c index d106e9e..2b2a9ef 100644 --- a/json_pointer.c +++ b/json_pointer.c @@ -8,10 +8,11 @@ #include "config.h" +#include "strerror_override.h" + #include #include #include -#include #include #include diff --git a/json_util.c b/json_util.c index 9a2f9ff..3a717b7 100644 --- a/json_util.c +++ b/json_util.c @@ -12,13 +12,14 @@ #include "config.h" #undef realloc +#include "strerror_override.h" + #include #include #include #include #include #include -#include #include #ifdef HAVE_SYS_TYPES_H diff --git a/random_seed.c b/random_seed.c index 3b61b77..cb086d3 100644 --- a/random_seed.c +++ b/random_seed.c @@ -9,6 +9,7 @@ * */ +#include "strerror_override.h" #include #include "config.h" #include "random_seed.h" @@ -128,7 +129,6 @@ retry: #include #include #include -#include #include #include diff --git a/tests/strerror_override.c b/strerror_override.c similarity index 96% rename from tests/strerror_override.c rename to strerror_override.c index 980cbb9..6cad0c0 100644 --- a/tests/strerror_override.c +++ b/strerror_override.c @@ -1,4 +1,4 @@ -#include +#include "strerror_override.h" /* * Override strerror() to get consistent output across platforms. @@ -54,7 +54,7 @@ static struct { #define PREFIX "ERRNO=" static char errno_buf[128] = PREFIX; -char *strerror(int errno_in) +char *_json_c_strerror(int errno_in) { int start_idx; char digbuf[20]; diff --git a/strerror_override.h b/strerror_override.h new file mode 100644 index 0000000..96e6bc6 --- /dev/null +++ b/strerror_override.h @@ -0,0 +1,12 @@ +#ifndef __STRERROR_OVERRIDE_H__ +#define __STRERROR_OVERRIDE_H__ + +#include "config.h" +#include + +#if ENABLE_STRERROR_OVERRIDE +char *_json_c_strerror(int errno_in); +#define strerror _json_c_strerror +#endif + +#endif /* __STRERROR_OVERRIDE_H__ */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 824ed30..917d20f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -52,7 +52,7 @@ EXTRA_DIST+= test2Formatted_plain.expected EXTRA_DIST+= test2Formatted_pretty.expected EXTRA_DIST+= test2Formatted_spaced.expected -test_util_file_SOURCES = test_util_file.c strerror_override.c +test_util_file_SOURCES = test_util_file.c testsubdir=testSubDir TESTS_ENVIRONMENT = top_builddir=$(top_builddir) diff --git a/tests/test_basic.test b/tests/test_basic.test index 3912732..154e036 100755 --- a/tests/test_basic.test +++ b/tests/test_basic.test @@ -11,5 +11,9 @@ fi filename=$(basename "$0") filename="${filename%.*}" -run_output_test $filename +# This is only for the test_util_file.test ; +# more stuff could be extended +cp -f "$srcdir/valid.json" . + +run_output_test $filename "$srcdir" exit $? diff --git a/tests/test_json_pointer.c b/tests/test_json_pointer.c index c3733de..cc96ab9 100644 --- a/tests/test_json_pointer.c +++ b/tests/test_json_pointer.c @@ -1,4 +1,4 @@ -#include +#include "strerror_override.h" #include #include #include diff --git a/tests/test_util_file.c b/tests/test_util_file.c index f98dce2..b4918be 100644 --- a/tests/test_util_file.c +++ b/tests/test_util_file.c @@ -1,4 +1,4 @@ -#include +#include "strerror_override.h" #include #include #include @@ -106,6 +106,7 @@ static void stat_and_cat(const char *file) buf[sb.st_size] = '\0'; printf("file[%s], size=%d, contents=%s\n", file, (int)sb.st_size, buf); free(buf); + close(d); } int main(int argc, char **argv) diff --git a/tests/test_util_file.test b/tests/test_util_file.test deleted file mode 100755 index 541aada..0000000 --- a/tests/test_util_file.test +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Common definitions -if test -z "$srcdir"; then - srcdir="${0%/*}" - test "$srcdir" = "$0" && srcdir=. - test -z "$srcdir" && srcdir=. -fi -. "$srcdir/test-defs.sh" - -cp -f "$srcdir/valid.json" . -run_output_test test_util_file "$srcdir" -_err=$? - -exit $_err diff --git a/tests/test_util_file.test b/tests/test_util_file.test new file mode 120000 index 0000000..58a13f4 --- /dev/null +++ b/tests/test_util_file.test @@ -0,0 +1 @@ +test_basic.test \ No newline at end of file