diff options
author | Sami Kerola | 2012-06-14 20:17:51 +0200 |
---|---|---|
committer | Sami Kerola | 2012-06-17 17:59:58 +0200 |
commit | 8f77d454a9c79e3de71575eb148fc32c767a2c39 (patch) | |
tree | c70f39462b32356b1c45a4936ab7679184f64d51 /include | |
parent | partx: use -s option for default output (diff) | |
download | kernel-qcow2-util-linux-8f77d454a9c79e3de71575eb148fc32c767a2c39.tar.gz kernel-qcow2-util-linux-8f77d454a9c79e3de71575eb148fc32c767a2c39.tar.xz kernel-qcow2-util-linux-8f77d454a9c79e3de71575eb148fc32c767a2c39.zip |
include [optutils]: add exclusive_option() inline function
The exclusive_option() will unify how exclusive options are
determined.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'include')
-rw-r--r-- | include/optutils.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/optutils.h b/include/optutils.h index f66d669c8..fae28fd0d 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 |