]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include [optutils]: add exclusive_option() inline function
authorSami Kerola <kerolasa@iki.fi>
Thu, 14 Jun 2012 18:17:51 +0000 (20:17 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 15:59:58 +0000 (17:59 +0200)
The exclusive_option() will unify how exclusive options are
determined.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include/optutils.h

index f66d669c86a6e6b8294abc2d818df8afd394db85..fae28fd0d12ea01017777a3fab006d753374bf6a 100644 (file)
@@ -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