| @@ -59,7 +59,8 @@ static struct | |||||
| /* clang-format on */ | /* clang-format on */ | ||||
| // Enabled during tests | // Enabled during tests | ||||
| int _json_c_strerror_enable = 0; | |||||
| static int _json_c_strerror_enable = 0; | |||||
| extern char *getenv(const char *name); // Avoid including stdlib.h | |||||
| #define PREFIX "ERRNO=" | #define PREFIX "ERRNO=" | ||||
| static char errno_buf[128] = PREFIX; | static char errno_buf[128] = PREFIX; | ||||
| @@ -70,6 +71,8 @@ char *_json_c_strerror(int errno_in) | |||||
| int ii, jj; | int ii, jj; | ||||
| if (!_json_c_strerror_enable) | if (!_json_c_strerror_enable) | ||||
| _json_c_strerror_enable = (getenv("_JSON_C_STRERROR_ENABLE") == NULL) ? -1 : 1; | |||||
| if (_json_c_strerror_enable == -1) | |||||
| return strerror(errno_in); | return strerror(errno_in); | ||||
| // Avoid standard functions, so we don't need to include any | // Avoid standard functions, so we don't need to include any | ||||
| @@ -37,6 +37,10 @@ foreach(TESTNAME | |||||
| test_object_iterator) | test_object_iterator) | ||||
| add_executable(${TESTNAME} ${TESTNAME}.c) | add_executable(${TESTNAME} ${TESTNAME}.c) | ||||
| if(${TESTNAME} STREQUAL test_util_file) | |||||
| # For output consistency, we need _json_c_strerror() in some tests: | |||||
| target_sources(${TESTNAME} PRIVATE ../strerror_override.c) | |||||
| endif() | |||||
| add_test(NAME ${TESTNAME} COMMAND ${PROJECT_SOURCE_DIR}/tests/${TESTNAME}.test) | add_test(NAME ${TESTNAME} COMMAND ${PROJECT_SOURCE_DIR}/tests/${TESTNAME}.test) | ||||
| # XXX using the non-target_ versions of these doesn't work :( | # XXX using the non-target_ versions of these doesn't work :( | ||||
| @@ -1,5 +1,7 @@ | |||||
| #!/bin/sh | #!/bin/sh | ||||
| export _JSON_C_STRERROR_ENABLE=1 | |||||
| # Common definitions | # Common definitions | ||||
| if test -z "$srcdir"; then | if test -z "$srcdir"; then | ||||
| srcdir="${0%/*}" | srcdir="${0%/*}" | ||||
| @@ -1,9 +1,8 @@ | |||||
| #include "strerror_override.h" | |||||
| #include "strerror_override_private.h" | |||||
| #ifdef NDEBUG | #ifdef NDEBUG | ||||
| #undef NDEBUG | #undef NDEBUG | ||||
| #endif | #endif | ||||
| #include <assert.h> | #include <assert.h> | ||||
| #include <errno.h> | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| @@ -320,8 +319,6 @@ static void test_wrong_inputs_set(void) | |||||
| int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
| { | { | ||||
| _json_c_strerror_enable = 1; | |||||
| test_example_get(); | test_example_get(); | ||||
| test_recursion_get(); | test_recursion_get(); | ||||
| test_wrong_inputs_get(); | test_wrong_inputs_get(); | ||||
| @@ -127,8 +127,6 @@ int main(int argc, char **argv) | |||||
| // json_object_to_file(file, obj); | // json_object_to_file(file, obj); | ||||
| // json_object_to_file_ext(file, obj, flags); | // json_object_to_file_ext(file, obj, flags); | ||||
| _json_c_strerror_enable = 1; | |||||
| const char *testdir; | const char *testdir; | ||||
| if (argc < 2) | if (argc < 2) | ||||
| { | { | ||||