From b1fccd03798da1930755557cb4516526cc09bb15 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 1 Feb 2014 18:08:24 -0500 Subject: Use strerror_r if available instead of sys_errlist. --- configure.ac | 16 +++++++++++++++- libdimension/bench/prtree.c | 6 +++--- libdimension/dimension-internal.h | 3 +-- libdimension/error.c | 10 ++++++++-- libdimension/platform.c | 4 +++- libdimension/tests/error.c | 4 +++- libdimension/tests/prtree.c | 8 ++++---- libdimension/tests/warning-as-error.c | 4 +++- libdimension/tests/warning.c | 4 +++- 9 files changed, 43 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 1141ac8..3942984 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -dnl Copyright (C) 2009-2012 Tavian Barnes +dnl Copyright (C) 2009-2014 Tavian Barnes dnl dnl This file is part of The Dimension Build Suite. dnl @@ -110,6 +110,20 @@ dnl Platform feature tests m4_include(ax_pthread.m4) AX_PTHREAD([], [AC_MSG_ERROR([pthread support not detected])]) +AC_MSG_CHECKING([for strerror_r]) +AC_RUN_IFELSE([ + AC_LANG_PROGRAM( + [ #include + #include ], + [ char buf@<:@256@:>@; + return strerror_r(ENOMEM, buf, 256); ] + )], + [AC_DEFINE([DMNSN_STRERROR_R], [1]) + AC_MSG_RESULT([yes])], + [AC_DEFINE([DMNSN_STRERROR_R], [0]) + AC_MSG_RESULT([no])] +) + AC_MSG_CHECKING([for sys_errlist]) AC_LINK_IFELSE([ AC_LANG_PROGRAM( diff --git a/libdimension/bench/prtree.c b/libdimension/bench/prtree.c index 9c1a5b1..11d831b 100644 --- a/libdimension/bench/prtree.c +++ b/libdimension/bench/prtree.c @@ -17,11 +17,11 @@ * along with this program. If not, see . * *************************************************************************/ -#include "../bvh.c" -#include "../prtree.c" +#include "../platform.c" #include "../threads.c" #include "../future.c" -#include "../platform.c" +#include "../bvh.c" +#include "../prtree.c" #include #include diff --git a/libdimension/dimension-internal.h b/libdimension/dimension-internal.h index 3f71fb1..99345c0 100644 --- a/libdimension/dimension-internal.h +++ b/libdimension/dimension-internal.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2012 Tavian Barnes * + * Copyright (C) 2009-2014 Tavian Barnes * * * * This file is part of The Dimension Library. * * * @@ -27,7 +27,6 @@ #ifndef DIMENSION_INTERNAL_H #define DIMENSION_INTERNAL_H -#define _GNU_SOURCE #include "dimension.h" #include "refcount-internal.h" #include "compiler-internal.h" diff --git a/libdimension/error.c b/libdimension/error.c index 371c7cd..1facc72 100644 --- a/libdimension/error.c +++ b/libdimension/error.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * + * Copyright (C) 2009-2014 Tavian Barnes * * * * This file is part of The Dimension Library. * * * @@ -25,6 +25,7 @@ #include "dimension-internal.h" #include +#include #include #include #include @@ -95,7 +96,12 @@ dmnsn_report_error(bool die, const char *func, const char *file, /* Print the value of errno */ if (err != 0) { fprintf(stderr, "Last error: %d", err); -#if DMNSN_SYS_ERRLIST +#if DMNSN_STRERROR_R + char errbuf[256]; + if (strerror_r(err, errbuf, 256) == 0) { + fprintf(stderr, " (%s)", errbuf); + } +#elif DMNSN_SYS_ERRLIST if (err >= 0 && err < sys_nerr) { fprintf(stderr, " (%s)", sys_errlist[err]); } diff --git a/libdimension/platform.c b/libdimension/platform.c index a27343d..d9d0e98 100644 --- a/libdimension/platform.c +++ b/libdimension/platform.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes * + * Copyright (C) 2010-2014 Tavian Barnes * * * * This file is part of The Dimension Library. * * * @@ -23,7 +23,9 @@ * Platform abstractions. */ +#define _GNU_SOURCE #include "dimension-internal.h" + #if HAVE_UNISTD_H #include #endif diff --git a/libdimension/tests/error.c b/libdimension/tests/error.c index 5a4d7fd..f4ffcee 100644 --- a/libdimension/tests/error.c +++ b/libdimension/tests/error.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * + * Copyright (C) 2009-2014 Tavian Barnes * * * * This file is part of The Dimension Test Suite. * * * @@ -21,10 +21,12 @@ #include "dimension.h" #include +#include int main(void) { + errno = ENOMEM; dmnsn_error("This error is expected."); return EXIT_SUCCESS; } diff --git a/libdimension/tests/prtree.c b/libdimension/tests/prtree.c index 2642f48..b2a2be6 100644 --- a/libdimension/tests/prtree.c +++ b/libdimension/tests/prtree.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2012 Tavian Barnes * + * Copyright (C) 2010-2014 Tavian Barnes * * * * This file is part of The Dimension Test Suite. * * * @@ -21,11 +21,11 @@ * Basic tests of PR-trees */ -#include "../bvh.c" -#include "../prtree.c" +#include "../platform.c" #include "../threads.c" #include "../future.c" -#include "../platform.c" +#include "../bvh.c" +#include "../prtree.c" #include #include diff --git a/libdimension/tests/warning-as-error.c b/libdimension/tests/warning-as-error.c index ce274d3..dfc08d6 100644 --- a/libdimension/tests/warning-as-error.c +++ b/libdimension/tests/warning-as-error.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * + * Copyright (C) 2009-2014 Tavian Barnes * * * * This file is part of The Dimension Test Suite. * * * @@ -21,11 +21,13 @@ #include "dimension.h" #include +#include int main(void) { dmnsn_die_on_warnings(true); + errno = ENOMEM; dmnsn_warning("This warning is expected."); return EXIT_SUCCESS; } diff --git a/libdimension/tests/warning.c b/libdimension/tests/warning.c index aecedd5..4e5dd75 100644 --- a/libdimension/tests/warning.c +++ b/libdimension/tests/warning.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * + * Copyright (C) 2009-2014 Tavian Barnes * * * * This file is part of The Dimension Test Suite. * * * @@ -21,10 +21,12 @@ #include "dimension.h" #include +#include int main(void) { + errno = ENOMEM; dmnsn_warning("This warning is expected."); return EXIT_SUCCESS; } -- cgit v1.2.3