]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: add a DEFNULL() macro to use NULL for empty args
authorWilly Tarreau <w@1wt.eu>
Mon, 19 Aug 2019 15:39:33 +0000 (17:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Aug 2019 18:21:00 +0000 (20:21 +0200)
It's sometimes convenient for debugging macros not to be forced to
explicitly pass NULL in an unused argument. This macro does this, it
replaces a missing arg with NULL.

include/common/standard.h

index cdefc9f5b3ebbbd8538e99762b7d84c852f62bc3..ffebac8ee7fb7db0f08e2eb60ad8ae3a59b54b83 100644 (file)
  * power of 2, and 0 otherwise */
 #define POWEROF2(x) (((x) & ((x)-1)) == 0)
 
+/* DEFNULL() returns either the argument as-is, or NULL if absent. This is for
+ * use in macros arguments.
+ */
+#define DEFNULL(...) _FIRST_ARG(NULL, ##__VA_ARGS__, NULL)
+#define _FIRST_ARG(a, b, ...) b
+
 /* operators to compare values. They're ordered that way so that the lowest bit
  * serves as a negation for the test and contains all tests that are not equal.
  */