@@ -325,8 +325,18 @@ char *sprint_time64(__s64 time, char *buf);
int do_batch(const char *name, bool force,
int (*cmd)(int argc, char *argv[], void *user), void *user);
+static inline void set_flag(unsigned int *p_flags, unsigned int flag, bool on)
+{
+ if (on)
+ *p_flags |= flag;
+ else
+ *p_flags &= ~flag;
+}
+
int parse_one_of(const char *msg, const char *realval, const char * const *list,
size_t len, int *p_err);
int parse_on_off(const char *msg, const char *realval, int *p_err);
+void parse_flag_on_off(const char *msg, const char *realval,
+ unsigned int *p_flags, unsigned int flag, int *p_ret);
#endif /* __UTILS_H__ */
@@ -1763,3 +1763,14 @@ int parse_on_off(const char *msg, const char *realval, int *p_err)
return parse_one_of(msg, realval, values_on_off, ARRAY_SIZE(values_on_off), p_err);
}
+
+void parse_flag_on_off(const char *msg, const char *realval,
+ unsigned int *p_flags, unsigned int flag, int *p_ret)
+{
+ int on_off = parse_on_off(msg, realval, p_ret);
+
+ if (*p_ret)
+ return;
+
+ set_flag(p_flags, flag, on_off);
+}
Some iplink code makes a heavy use of code that sets or unsets a certain flag depending on whether "on" or "off" of specified. Extract this logic into a new function, parse_flag_on_off(). The bit that sets or clears a flag will be useful separately, so add it to a named function, set_flag(). Signed-off-by: Petr Machata <me@pmachata.org> --- include/utils.h | 10 ++++++++++ lib/utils.c | 11 +++++++++++ 2 files changed, 21 insertions(+)