]> arthur.barton.de Git - netdata.git/commitdiff
workaround strerror_r compatibility between glibc and musl
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Mon, 26 Sep 2016 22:32:26 +0000 (01:32 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Mon, 26 Sep 2016 22:32:26 +0000 (01:32 +0300)
src/log.c

index 3d8ebc7ba0cd0e81c791cf14ed9e837fac1ba3a8..f22ec4d37b3bd80a6980e9359e40eb0c90f137ea 100644 (file)
--- 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