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. --- libdimension/error.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libdimension/error.c') 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]); } -- cgit v1.2.3