]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: add a new macro DEFVAL() to provide a default argument
authorWilly Tarreau <w@1wt.eu>
Thu, 28 Nov 2024 14:11:46 +0000 (15:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 3 Dec 2024 18:45:08 +0000 (19:45 +0100)
This is like DEFZERO and DEFNULL, but this one allows to specify the
default value to be used as the first argument.

include/haproxy/tools-t.h

index 34e2fd818f6f8e6d446adc6cc8dee157f1d99ccd..ef3e136a4fa03793a33586d39bf2cd023e1c7b49 100644 (file)
 /* return the largest possible integer of type <ret>, with all bits set */
 #define MAX_RANGE(ret) (~(typeof(ret))0)
 
+/* DEFVAL() returns either the second argument as-is, or <def> if absent. This
+ * is for use in macros arguments.
+ */
+#define DEFVAL(_def,...) _FIRST_ARG(NULL, ##__VA_ARGS__, (_def))
+
 /* 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 DEFNULL(...) DEFVAL(NULL, ##__VA_ARGS__)
 
 /* DEFZERO() returns either the argument as-is, or 0 if absent. This is for
  * use in macros arguments.
  */
-#define DEFZERO(...) _FIRST_ARG(NULL, ##__VA_ARGS__, 0)
+#define DEFZERO(...) DEFVAL(0, ##__VA_ARGS__)
 
 #define _FIRST_ARG(a, b, ...) b