Whamcloud - gitweb
LU-6210 utils: Use C99 struct initializer in parse_opts() 17/27817/2
authorSteve Guminski <stephenx.guminski@intel.com>
Mon, 22 May 2017 12:00:35 +0000 (08:00 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 19 Jul 2017 03:32:09 +0000 (03:32 +0000)
This patch makes no functional changes.  The long_opt initializer in
parse_opts() is updated to C99 syntax, and renamed to long_opts for
consistency.

C89 positional initializers require values to be placed in the
correct order. This will cause errors if the fields of the struct
definition are reordered or fields are added or removed. C99 named
initializers avoid this problem, and also automatically clear any
values that are not explicitly set.

Test-Parameters: trivial
Signed-off-by: Steve Guminski <stephenx.guminski@intel.com>
Change-Id: Id3f1540c33cbd5db33a4a0eb69a89672eac7f713
Reviewed-on: https://review.whamcloud.com/27817
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
lustre/utils/mount_lustre.c

index eddec39..14ea849 100644 (file)
@@ -599,16 +599,15 @@ static void set_defaults(struct mount_opts *mop)
 
 static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
 {
 
 static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
 {
-       static struct option long_opt[] = {
-               {"fake", 0, 0, 'f'},
-               {"force", 0, 0, 1},
-               {"help", 0, 0, 'h'},
-               {"nomtab", 0, 0, 'n'},
-               {"options", 1, 0, 'o'},
-               {"verbose", 0, 0, 'v'},
-               {"version", 0, 0, 'V'},
-               {0, 0, 0, 0}
-       };
+       static struct option long_opts[] = {
+       { .val = 1,     .name = "force",        .has_arg = no_argument },
+       { .val = 'f',   .name = "fake",         .has_arg = no_argument },
+       { .val = 'h',   .name = "help",         .has_arg = no_argument },
+       { .val = 'n',   .name = "nomtab",       .has_arg = no_argument },
+       { .val = 'o',   .name = "options",      .has_arg = required_argument },
+       { .val = 'v',   .name = "verbose",      .has_arg = no_argument },
+       { .val = 'V',   .name = "version",      .has_arg = no_argument },
+       { .name = NULL } };
        char real_path[PATH_MAX] = {'\0'};
        FILE *f;
        char path[256], name[256];
        char real_path[PATH_MAX] = {'\0'};
        FILE *f;
        char path[256], name[256];
@@ -617,7 +616,7 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
        int opt, rc;
 
        while ((opt = getopt_long(argc, argv, "fhno:vV",
        int opt, rc;
 
        while ((opt = getopt_long(argc, argv, "fhno:vV",
-                                 long_opt, NULL)) != EOF){
+                                 long_opts, NULL)) != EOF){
                switch (opt) {
                case 1:
                        ++mop->mo_force;
                switch (opt) {
                case 1:
                        ++mop->mo_force;