]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: use exclusive_option()
authorSami Kerola <kerolasa@iki.fi>
Fri, 15 Jun 2012 20:56:45 +0000 (22:56 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 15:59:59 +0000 (17:59 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/losetup.c

index 3c3229989b9221945585a372ae83dd391116cee7..bc9e6c68ae6ccd2f6419c8f6cdbf6f4b17fad232 100644 (file)
@@ -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;