From 94df2efe2d2221bf0c4d77510142c95283d76f2b Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Wed, 10 May 2023 15:19:49 +0200 Subject: Clean-up error message and test Refactoring error messages: - standardize error messages and functions - return on error instead of exit - test error when target doesn't exist - include ability to capture stderr and stdout in the tests --- common/util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'common') diff --git a/common/util.h b/common/util.h index 102b55b..ad2192b 100644 --- a/common/util.h +++ b/common/util.h @@ -8,6 +8,7 @@ #include #include +#include #define BIT(n) (1UL << (n)) @@ -33,6 +34,17 @@ void debug(const char *format, ...); exit(EXIT_FAILURE); \ } while (0) +#define ret_err(e, ...) \ + do { \ + if (errno == 0) { \ + err(__VA_ARGS__); \ + } else { \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, ": %s\n", strerror(errno)); \ + } \ + return (e); \ + } while (0) + /** * From the Linux kernel, include/linux/log2.h: * -- cgit v1.2.3