]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkzone: use optutils.h to check mutually exclusive options
authorKarel Zak <kzak@redhat.com>
Fri, 24 Feb 2017 10:59:53 +0000 (11:59 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 24 Feb 2017 10:59:53 +0000 (11:59 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/blkzone.c

index b9f1ed75283e47f4560b9ad1890b0f83b74d003c..e2c33770cbd589a9b36eeeb4fcb3634609390146 100644 (file)
@@ -42,6 +42,7 @@
 #include "closestream.h"
 #include "blkdev.h"
 #include "sysfs.h"
+#include "optutils.h"
 
 struct blkzone_control;
 
@@ -305,8 +306,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 
        fputs(USAGE_OPTIONS, out);
        fputs(_(" -o, --offset <sector>  start sector of zone to act (in 512-byte sectors)\n"), out);
-       fputs(_(" -l, --length <sectors>  maximum sectors to act (in 512-byte sectors)\n"), out);
-       fputs(_(" -c, --count <number>  maximum number of zones\n"), out);
+       fputs(_(" -l, --length <sectors> maximum sectors to act (in 512-byte sectors)\n"), out);
+       fputs(_(" -c, --count <number>   maximum number of zones\n"), out);
        fputs(_(" -v, --verbose          display more details\n"), out);
        fputs(USAGE_SEPARATOR, out);
        fputs(USAGE_HELP, out);
@@ -328,13 +329,19 @@ int main(int argc, char **argv)
 
        static const struct option longopts[] = {
            { "help",    no_argument,       NULL, 'h' },
-           { "count",  required_argument, NULL, 'c' }, /* max #of zones to operate on */
+           { "count",   required_argument, NULL, 'c' }, /* max #of zones to operate on */
            { "length",  required_argument, NULL, 'l' }, /* max of sectors to operate on */
            { "offset",  required_argument, NULL, 'o' }, /* starting LBA */
            { "verbose", no_argument,       NULL, 'v' },
            { "version", no_argument,       NULL, 'V' },
            { NULL, 0, NULL, 0 }
        };
+       static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
+               { 'c', 'l' },
+               { 0 }
+       };
+       int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+
 
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
@@ -350,6 +357,9 @@ int main(int argc, char **argv)
        }
 
        while ((c = getopt_long(argc, argv, "hc:l:o:vV", longopts, NULL)) != -1) {
+
+               err_exclusive_options(c, longopts, excl, excl_st);
+
                switch (c) {
                case 'h':
                        usage(stdout);
@@ -380,9 +390,6 @@ int main(int argc, char **argv)
        if (!ctl.command)
                errx(EXIT_FAILURE, _("no command specified"));
 
-       if (ctl.count && ctl.length)
-               errx(EXIT_FAILURE, _("zone count and number of sectors cannot be specified together"));
-
        if (optind == argc)
                errx(EXIT_FAILURE, _("no device specified"));
        ctl.devname = argv[optind++];