From: Sami Kerola Date: Thu, 14 Jun 2012 18:17:51 +0000 (+0200) Subject: include [optutils]: add exclusive_option() inline function X-Git-Tag: v2.22-rc1~267^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8f77d454a9c79e3de71575eb148fc32c767a2c39;p=thirdparty%2Futil-linux.git include [optutils]: add exclusive_option() inline function The exclusive_option() will unify how exclusive options are determined. Signed-off-by: Sami Kerola --- diff --git a/include/optutils.h b/include/optutils.h index f66d669c86..fae28fd0d1 100644 --- a/include/optutils.h +++ b/include/optutils.h @@ -1,6 +1,9 @@ #ifndef UTIL_LINUX_OPTUTILS_H #define UTIL_LINUX_OPTUTILS_H +#include "c.h" +#include "nls.h" + static inline const char *option_to_longopt(int c, const struct option *opts) { const struct option *o; @@ -11,5 +14,21 @@ static inline const char *option_to_longopt(int c, const struct option *opts) return NULL; } +#ifndef OPTUTILS_EXIT_CODE +# define OPTUTILS_EXIT_CODE EXIT_FAILURE +#endif +static inline void exclusive_option(int *what, const int how, + const char *errmesg) +{ + if (*what == 0) { + *what = how; + return; + } + if (*what == how) + return; + errx(OPTUTILS_EXIT_CODE, + _("options %s are mutually exclusive"), errmesg); +} + #endif