From: Steve Guminski Date: Mon, 22 May 2017 12:00:35 +0000 (-0400) Subject: LU-6210 utils: Use C99 struct initializer in parse_opts() X-Git-Tag: 2.10.51~54 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F27817%2F2;p=fs%2Flustre-release.git LU-6210 utils: Use C99 struct initializer in parse_opts() 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 Change-Id: Id3f1540c33cbd5db33a4a0eb69a89672eac7f713 Reviewed-on: https://review.whamcloud.com/27817 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: James Simmons --- diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index eddec39..14ea849 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -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 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]; @@ -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", - long_opt, NULL)) != EOF){ + long_opts, NULL)) != EOF){ switch (opt) { case 1: ++mop->mo_force;