From 96801c4826238b2db665910ef57c4811e1a7d21b Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 15 Jun 2012 22:56:45 +0200 Subject: losetup: use exclusive_option() Signed-off-by: Sami Kerola --- sys-utils/losetup.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'sys-utils/losetup.c') diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 3c3229989..bc9e6c68a 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -20,6 +20,9 @@ #include "loopdev.h" #include "xgetpass.h" #include "closestream.h" +#include "optutils.h" + +#define EXCL_ERROR "--{all,associated,set-capacity,detach,detach-all,find}" enum { A_CREATE = 1, /* setup a new device */ @@ -211,6 +214,17 @@ int main(int argc, char **argv) uint64_t offset = 0, sizelimit = 0; int res = 0, showdev = 0, lo_flags = 0; + enum { + EXCL_NONE, + EXCL_ALL, + EXCL_ASSOCIATED, + EXCL_SET_CAPACITY, + EXCL_DETACH, + EXCL_DETACH_ALL, + EXCL_FIND + }; + int excl_any = EXCL_NONE; + enum { OPT_SIZELIMIT = CHAR_MAX + 1, OPT_SHOW @@ -245,17 +259,13 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, "ac:d:De:E:fhj:o:p:PrvV", longopts, NULL)) != -1) { - - if (act && strchr("acdDfj", c)) - errx(EXIT_FAILURE, - _("the options %s are mutually exclusive"), - "--{all,associated,set-capacity,detach,detach-all,find}"); - switch (c) { case 'a': + exclusive_option(&excl_any, EXCL_ALL, EXCL_ERROR); act = A_SHOW; break; case 'c': + exclusive_option(&excl_any, EXCL_SET_CAPACITY, EXCL_ERROR); act = A_SET_CAPACITY; loopcxt_set_device(&lc, optarg); break; @@ -263,10 +273,12 @@ int main(int argc, char **argv) lo_flags |= LO_FLAGS_READ_ONLY; break; case 'd': + exclusive_option(&excl_any, EXCL_DETACH, EXCL_ERROR); act = A_DELETE; loopcxt_set_device(&lc, optarg); break; case 'D': + exclusive_option(&excl_any, EXCL_DETACH_ALL, EXCL_ERROR); act = A_DELETE_ALL; break; case 'E': @@ -274,12 +286,14 @@ int main(int argc, char **argv) encryption = optarg; break; case 'f': + exclusive_option(&excl_any, EXCL_FIND, EXCL_ERROR); act = A_FIND_FREE; break; case 'h': usage(stdout); break; case 'j': + exclusive_option(&excl_any, EXCL_ASSOCIATED, EXCL_ERROR); act = A_SHOW; file = optarg; break; -- cgit v1.2.3-55-g7522