mirror of
https://github.com/json-c/json-c.git
synced 2026-04-05 05:19:07 +08:00
PR #336: since we can't use function overriding (due to problems with it on
OSX) always include the _json_c_strerror function but only enable it with a flag during tests.
This commit is contained in:
@@ -51,14 +51,8 @@ libjson_c_la_SOURCES = \
|
|||||||
json_visit.c \
|
json_visit.c \
|
||||||
linkhash.c \
|
linkhash.c \
|
||||||
printbuf.c \
|
printbuf.c \
|
||||||
random_seed.c
|
random_seed.c \
|
||||||
|
|
||||||
if ENABLE_STRERROR_OVERRIDE
|
|
||||||
libjson_cinclude_HEADERS+= \
|
|
||||||
strerror_override.h
|
|
||||||
libjson_c_la_SOURCES+= \
|
|
||||||
strerror_override.c
|
strerror_override.c
|
||||||
endif
|
|
||||||
|
|
||||||
distclean-local:
|
distclean-local:
|
||||||
-rm -rf $(testsubdir)
|
-rm -rf $(testsubdir)
|
||||||
|
|||||||
16
configure.ac
16
configure.ac
@@ -23,22 +23,6 @@ else
|
|||||||
AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable])
|
AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable])
|
||||||
fi
|
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
|
# enable silent build by default
|
||||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#define STERROR_OVERRIDE_IMPL 1
|
||||||
#include "strerror_override.h"
|
#include "strerror_override.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -52,6 +53,9 @@ static struct {
|
|||||||
{ 0, (char *)0 }
|
{ 0, (char *)0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Enabled during tests
|
||||||
|
int _json_c_strerror_enable = 0;
|
||||||
|
|
||||||
#define PREFIX "ERRNO="
|
#define PREFIX "ERRNO="
|
||||||
static char errno_buf[128] = PREFIX;
|
static char errno_buf[128] = PREFIX;
|
||||||
char *_json_c_strerror(int errno_in)
|
char *_json_c_strerror(int errno_in)
|
||||||
@@ -60,6 +64,9 @@ char *_json_c_strerror(int errno_in)
|
|||||||
char digbuf[20];
|
char digbuf[20];
|
||||||
int ii, jj;
|
int ii, jj;
|
||||||
|
|
||||||
|
if (!_json_c_strerror_enable)
|
||||||
|
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
|
||||||
// headers, or guess at signatures.
|
// headers, or guess at signatures.
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#ifndef __STRERROR_OVERRIDE_H__
|
#ifndef _json_strerror_override_h_
|
||||||
#define __STRERROR_OVERRIDE_H__
|
#define _json_strerror_override_h_
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#if ENABLE_STRERROR_OVERRIDE
|
|
||||||
char *_json_c_strerror(int errno_in);
|
char *_json_c_strerror(int errno_in);
|
||||||
|
|
||||||
|
#ifndef STRERROR_OVERRIDE_IMPL
|
||||||
#define strerror _json_c_strerror
|
#define strerror _json_c_strerror
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __STRERROR_OVERRIDE_H__ */
|
#endif /* _json_strerror_override_h_ */
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "strerror_override.h"
|
#include "strerror_override.h"
|
||||||
|
#include "strerror_override_private.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -280,6 +281,8 @@ static void test_wrong_inputs_set()
|
|||||||
|
|
||||||
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();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "strerror_override.h"
|
#include "strerror_override.h"
|
||||||
|
#include "strerror_override_private.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@@ -114,6 +115,8 @@ 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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user