From 61c35f1909b2496c7edac288a59f75604c7c179e Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 13 Dec 2016 23:34:36 +0100 Subject: [PATCH 1/1] error: Actually check for strerror in configure and fix GNU-specific code. D'oh! --- configure.ac | 3 +++ src/utils/error.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 521f0ac..4d7ccae 100644 --- a/configure.ac +++ b/configure.ac @@ -446,6 +446,9 @@ if test "x$have_struct_ucred" != "xyes"; then AC_MSG_RESULT([$have_struct_ucred]) fi +dnl Only check this after potentially defining _GNU_SOURCE. +AC_FUNC_STRERROR_R + dnl Testing. PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [unit_tests="yes"], [unit_tests="no"]) diff --git a/src/utils/error.c b/src/utils/error.c index f0a4827..6d23c6b 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -298,10 +298,12 @@ sdb_error_parse_priority(char *prio) char * sdb_strerror(int errnum, char *strerrbuf, size_t buflen) { + *strerrbuf = '\0'; + #if STRERROR_R_CHAR_P { char *tmp = strerror_r(errnum, strerrbuf, buflen); - if (*strerrbuf = '\0') { + if (*strerrbuf == '\0') { if (tmp && (tmp != strerrbuf) && (*tmp != '\0')) strncpy(strerrbuf, tmp, buflen); else -- 2.30.2