summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/util.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/util/util.h b/src/util/util.h
index 9e118c2..67c47e0 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -5,10 +5,21 @@
#include <stddef.h>
#include <err.h>
-#define WARN1(x) do { warn("asound: %s %s", __func__, x); } while (0)
-#define WARN(x, ...) do { warn("asound: %s " x, __func__, ##__VA_ARGS__); } while (0)
-#define WARNX1(x) do { warnx("asound: %s %s", __func__, x); } while (0)
-#define WARNX(x, ...) do { warnx("asound: %s " x, __func__, ##__VA_ARGS__); } while (0)
+static inline int
+do_debug(void)
+{
+ static int debug = -1;
+ if (debug == -1) {
+ const char *env = getenv("ASOUND_DEBUG");
+ debug = (env && !!strcmp(env, "0"));
+ }
+ return debug;
+}
+
+#define WARN1(x) do { if (do_debug()) warn("asound: %s %s", __func__, x); } while(0)
+#define WARN(x, ...) do { if (do_debug()) warn("asound: %s " x, __func__, ##__VA_ARGS__); } while (0)
+#define WARNX1(x) do { if (do_debug()) warnx("asound: %s %s", __func__, x); } while (0)
+#define WARNX(x, ...) do { if (do_debug()) warnx("asound: %s " x, __func__, ##__VA_ARGS__); } while (0)
#define ERRX1(x, y) do { errx(x, "asound: %s %s", __func__, y); } while (0)
#define ERRX(x, y, ...) do { errx(x, "asound: %s " y, __func__, ##__VA_ARGS__); } while (0)
#define ERR(x, y, ...) do { err(x, "asound: %s " y, __func__, ##__VA_ARGS__); } while (0)