[lib] add AUBIO_STRERR to log system error messages
authorPaul Brossier <piem@piem.org>
Sat, 22 Dec 2018 23:06:32 +0000 (00:06 +0100)
committerPaul Brossier <piem@piem.org>
Sat, 22 Dec 2018 23:06:32 +0000 (00:06 +0100)
src/aubio_priv.h

index fa59571..ab6afb2 100644 (file)
 #include <string.h>
 #endif
 
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 #ifdef HAVE_LIMITS_H
 #include <limits.h> // for CHAR_BIT, in C99 standard
 #endif
@@ -330,6 +334,18 @@ uint_t aubio_log(sint_t level, const char_t *fmt, ...);
 #define AUBIO_STRERROR(errno,buf,len) strerror_s(buf, len, errno)
 #endif
 
+#ifdef HAVE_C99_VARARGS_MACROS
+#define AUBIO_STRERR(...)            \
+    char errorstr[256]; \
+    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \
+    AUBIO_ERR(__VA_ARGS__)
+#else
+#define AUBIO_STRERR(format, args...)   \
+    char errorstr[256]; \
+    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \
+    AUBIO_ERR(format, ##args)
+#endif
+
 /* handy shortcuts */
 #define DB2LIN(g) (POW(10.0,(g)*0.05f))
 #define LIN2DB(v) (20.0*LOG10(v))