mirror of
https://github.com/json-c/json-c.git
synced 2026-03-27 00:49:07 +08:00
build: make strerror() override-able
If we want to override `strerror()` in libjson-c to make tests consistent across platforms, we need to do it build-wide as configure/build option. Apple linkers make it really hard to override functions at link-time, and this seems to be locked down on travis-ci.org [ for security reasons I assume ]. While I got it to work locally, it did not work when running on travis. Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
16
configure.ac
16
configure.ac
@@ -23,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])])
|
||||
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "strerror_override.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "printbuf.h"
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "strerror_override.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
#include "config.h"
|
||||
#undef realloc
|
||||
|
||||
#include "strerror_override.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "strerror_override.h"
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
#include "random_seed.h"
|
||||
@@ -128,7 +129,6 @@ retry:
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <errno.h>
|
||||
#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];
|
||||
12
strerror_override.h
Normal file
12
strerror_override.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __STRERROR_OVERRIDE_H__
|
||||
#define __STRERROR_OVERRIDE_H__
|
||||
|
||||
#include "config.h"
|
||||
#include <errno.h>
|
||||
|
||||
#if ENABLE_STRERROR_OVERRIDE
|
||||
char *_json_c_strerror(int errno_in);
|
||||
#define strerror _json_c_strerror
|
||||
#endif
|
||||
|
||||
#endif /* __STRERROR_OVERRIDE_H__ */
|
||||
@@ -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)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <errno.h>
|
||||
#include "strerror_override.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <errno.h>
|
||||
#include "strerror_override.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
Reference in New Issue
Block a user