[PATCH 5/9] option: add support for options with 'zero is infinity'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For some options with a numerical value, it is sometimes desirable,
to easily specify we want the maximum possible value.

This patch allow to interpret '=0' as meaning the maximum value.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 lib.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib.c b/lib.c
index 5fda4b029..6352b4e93 100644
--- a/lib.c
+++ b/lib.c
@@ -509,8 +509,11 @@ static int handle_simple_switch(const char *arg, const struct flag *flags)
 	return 0;
 }
 
+
+#define	OPTNUM_ZERO_IS_INF		1
+
 #define OPT_NUMERIC(NAME, TYPE, FUNCTION)	\
-static int opt_##NAME(char *arg, const char *name, TYPE *ptr)	\
+static int opt_##NAME(char *arg, const char *name, TYPE *ptr, int flag)	\
 {									\
 	char *opt;							\
 	char *end;							\
@@ -523,6 +526,8 @@ static int opt_##NAME(char *arg, const char *name, TYPE *ptr)	\
 	if (*end != '\0' || end == opt) {				\
 			die("error: missing argument to \"%s\"", name);	\
 	}								\
+	if ((flag & OPTNUM_ZERO_IS_INF) && val == 0)			\
+		val = ~val;						\
 	*ptr = val;							\
 	return 1;							\
 }
-- 
2.14.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux