]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Change the strerror_override handling to check $_JSON_C_STRERROR_OVERRIDE instead...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 4 Jul 2020 18:56:15 +0000 (18:56 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 4 Jul 2020 18:58:00 +0000 (18:58 +0000)
strerror_override.c
tests/CMakeLists.txt
tests/test_basic.test
tests/test_json_pointer.c
tests/test_util_file.c

index a93be38fc782a64fed24e975c8bb458ab13e58d2..7a262f7bfc57a1dbd1402e9e68a4c5b7c4c660f5 100644 (file)
@@ -59,7 +59,8 @@ static struct
 /* clang-format on */
 
 // 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="
 static char errno_buf[128] = PREFIX;
@@ -70,6 +71,8 @@ char *_json_c_strerror(int errno_in)
        int ii, jj;
 
        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);
 
        // Avoid standard functions, so we don't need to include any
index a871573909d46a982c9c3e7192430f2666a7ec13..125f615765aa58bc363a0fedaf0878977f6c2689 100644 (file)
@@ -37,6 +37,10 @@ foreach(TESTNAME
        test_object_iterator)
 
 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)
 
 # XXX using the non-target_ versions of these doesn't work :(
index 154e036d513ec121e012ef3d8f6166f3942e1fc2..474e7a82741655e22d82c46cdc61e98068285aec 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+export _JSON_C_STRERROR_ENABLE=1
+
 # Common definitions
 if test -z "$srcdir"; then
     srcdir="${0%/*}"
index 34fa2026c6909e7399d059bd51da881b7235b28b..3174c87e6805b9a0b3cb90742c0ed54da06141e0 100644 (file)
@@ -1,9 +1,8 @@
-#include "strerror_override.h"
-#include "strerror_override_private.h"
 #ifdef NDEBUG
 #undef NDEBUG
 #endif
 #include <assert.h>
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -320,8 +319,6 @@ static void test_wrong_inputs_set(void)
 
 int main(int argc, char **argv)
 {
-       _json_c_strerror_enable = 1;
-
        test_example_get();
        test_recursion_get();
        test_wrong_inputs_get();
index 9d5066375acae3f43bf703d13babdff8fbbbf9f8..9150586e387836a0425a2adbb4da1dc956a07ab7 100644 (file)
@@ -127,8 +127,6 @@ int main(int argc, char **argv)
        //      json_object_to_file(file, obj);
        //      json_object_to_file_ext(file, obj, flags);
 
-       _json_c_strerror_enable = 1;
-
        const char *testdir;
        if (argc < 2)
        {