Re: [PATCH iproute2-next v2 02/11] lib: Add parse_one_of(), parse_on_off()

2020-10-31 Thread Petr Machata
David Ahern writes: > On 10/30/20 6:29 AM, Petr Machata wrote: >> +int parse_on_off(const char *msg, const char *realval, int *p_err) >> +{ >> +static const char * const values_on_off[] = { "off", "on" }; >> + >> +return parse_one_of(msg, realval, values_on_off, >> ARRAY_SIZE(values_on

Re: [PATCH iproute2-next v2 02/11] lib: Add parse_one_of(), parse_on_off()

2020-10-31 Thread David Ahern
On 10/30/20 6:29 AM, Petr Machata wrote: > diff --git a/lib/utils.c b/lib/utils.c > index 9815e328c9e0..930877ae0f0d 100644 > --- a/lib/utils.c > +++ b/lib/utils.c > @@ -1735,3 +1735,31 @@ int do_batch(const char *name, bool force, > > return ret; > } > + > +int parse_one_of(const char *ms

[PATCH iproute2-next v2 02/11] lib: Add parse_one_of(), parse_on_off()

2020-10-30 Thread Petr Machata
Take from the macsec code parse_one_of() and adapt so that it passes the primary result as the main return value, and error result through a pointer. That is the simplest way to make the code reusable across data types without introducing extra magic. Also from macsec take the specialization of pa