Browse Source

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>
tags/json-c-0.13-20171207
Alexandru Ardelean 8 years ago
parent
commit
fb72160caf
11 changed files with 46 additions and 9 deletions
  1. +6
    -0
      Makefile.am
  2. +16
    -0
      configure.ac
  3. +2
    -1
      json_object.c
  4. +2
    -1
      json_pointer.c
  5. +2
    -1
      json_util.c
  6. +1
    -1
      random_seed.c
  7. +2
    -2
      strerror_override.c
  8. +12
    -0
      strerror_override.h
  9. +1
    -1
      tests/Makefile.am
  10. +1
    -1
      tests/test_json_pointer.c
  11. +1
    -1
      tests/test_util_file.c

+ 6
- 0
Makefile.am View File

@@ -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
- 0
configure.ac View File

@@ -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])])



+ 2
- 1
json_object.c View File

@@ -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"


+ 2
- 1
json_pointer.c View File

@@ -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>



+ 2
- 1
json_util.c View File

@@ -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


+ 1
- 1
random_seed.c View File

@@ -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>



tests/strerror_override.c → strerror_override.c View File

@@ -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
- 0
strerror_override.h View 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__ */

+ 1
- 1
tests/Makefile.am View File

@@ -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
- 1
tests/test_json_pointer.c View File

@@ -1,4 +1,4 @@
#include <errno.h>
#include "strerror_override.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>


+ 1
- 1
tests/test_util_file.c View File

@@ -1,4 +1,4 @@
#include <errno.h>
#include "strerror_override.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>


Loading…
Cancel
Save