@cryptotaxi247 / netdata-1 / commits / 18f2fd2eb

workaround strerror_r compatibility between glibc and musl

Costa Tsaousis (ktsaou) committed Sep 27, 2016 at 01:32 UTC 18f2fd2eb56f18ba5aa7c0af14df56b9665b0d0b
1 file changed +11 -6
src/log.c
+11 -6
@@ -266,6 +266,16 @@ void info_int( const char *file, const char *function, const unsigned long line,
266 // ----------------------------------------------------------------------------
267 // error log
268
269 +// what a trick!
270 +// http://stackoverflow.com/questions/479207/function-overloading-in-c
271 +static const char *strerror_result_int(int a, const char *b) { (void)a; return b; }
272 +static const char *strerror_result_string(const char *a, const char *b) { (void)b; return a; }
273 +
274 +#define strerror_result(a, b) _Generic((a), \
275 + int: strerror_result_int, \
276 + char *: strerror_result_string \
277 + )(a, b)
278 +
279 void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... )
280 {
281 va_list args;
@@ -283,12 +293,7 @@ void error_int( const char *prefix, const char *file, const char *function, cons
293
294 if(errno) {
295 char buf[1024];
286 -#if ((_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE)
287 - strerror_r(errno, buf, 1023);
288 - fprintf(stderr, " (errno %d, %s)\n", errno, buf);
289 -#else
290 - fprintf(stderr, " (errno %d, %s)\n", errno, strerror_r(errno, buf, 1023));
291 -#endif
296 + fprintf(stderr, " (errno %d, %s)\n", errno, strerror_result(strerror_r(errno, buf, 1023), buf));
297 errno = 0;
298 }
299 else