From: Costa Tsaousis (ktsaou) Date: Mon, 26 Sep 2016 22:32:26 +0000 (+0300) Subject: workaround strerror_r compatibility between glibc and musl X-Git-Tag: v1.4.0~19^2~5 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=18f2fd2eb56f18ba5aa7c0af14df56b9665b0d0b;p=netdata.git workaround strerror_r compatibility between glibc and musl --- diff --git a/src/log.c b/src/log.c index 3d8ebc7b..f22ec4d3 100644 --- a/src/log.c +++ b/src/log.c @@ -266,6 +266,16 @@ void info_int( const char *file, const char *function, const unsigned long line, // ---------------------------------------------------------------------------- // error log +// what a trick! +// http://stackoverflow.com/questions/479207/function-overloading-in-c +static const char *strerror_result_int(int a, const char *b) { (void)a; return b; } +static const char *strerror_result_string(const char *a, const char *b) { (void)b; return a; } + +#define strerror_result(a, b) _Generic((a), \ + int: strerror_result_int, \ + char *: strerror_result_string \ + )(a, b) + void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... ) { va_list args; @@ -283,12 +293,7 @@ void error_int( const char *prefix, const char *file, const char *function, cons if(errno) { char buf[1024]; -#if ((_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE) - strerror_r(errno, buf, 1023); - fprintf(stderr, " (errno %d, %s)\n", errno, buf); -#else - fprintf(stderr, " (errno %d, %s)\n", errno, strerror_r(errno, buf, 1023)); -#endif + fprintf(stderr, " (errno %d, %s)\n", errno, strerror_result(strerror_r(errno, buf, 1023), buf)); errno = 0; } else