Message ID | 20190723062713.20570-1-yongcheng.yang@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] nfs4_getfacl: return 1 for unknown option and won't use '-?' anymore | expand |
On Tue, Jul 23, 2019 at 02:27:12PM +0800, Yongcheng Yang wrote: > The getopt_long() function will return '?' if encounters an option > character that was not in optstring. So it's impossible to tell the > option '-?' from an unrecognized option. Don't mention it in Usage. Thanks, both patches applied.--b. > > Signed-off-by: Yongcheng Yang <yongcheng.yang@gmail.com> > --- > nfs4_getfacl/nfs4_getfacl.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/nfs4_getfacl/nfs4_getfacl.c b/nfs4_getfacl/nfs4_getfacl.c > index 4df2b04..2f57866 100644 > --- a/nfs4_getfacl/nfs4_getfacl.c > +++ b/nfs4_getfacl/nfs4_getfacl.c > @@ -88,10 +88,14 @@ int main(int argc, char **argv) > case 'c': > ignore_comment = 1; > break; > - default: > + case 'h': > usage(1); > res = 0; > goto out; > + case '?': > + default: > + usage(0); > + goto out; > } > } > > @@ -131,7 +135,7 @@ static void usage(int label) > { > if (label) > fprintf(stderr, "%s %s -- get NFSv4 file or directory access control lists.\n", execname, VERSION); > - fprintf(stderr, "Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -?, -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname); > + fprintf(stderr, "Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname); > } > > static void more_help() > -- > 2.20.1
diff --git a/nfs4_getfacl/nfs4_getfacl.c b/nfs4_getfacl/nfs4_getfacl.c index 4df2b04..2f57866 100644 --- a/nfs4_getfacl/nfs4_getfacl.c +++ b/nfs4_getfacl/nfs4_getfacl.c @@ -88,10 +88,14 @@ int main(int argc, char **argv) case 'c': ignore_comment = 1; break; - default: + case 'h': usage(1); res = 0; goto out; + case '?': + default: + usage(0); + goto out; } } @@ -131,7 +135,7 @@ static void usage(int label) { if (label) fprintf(stderr, "%s %s -- get NFSv4 file or directory access control lists.\n", execname, VERSION); - fprintf(stderr, "Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -?, -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname); + fprintf(stderr, "Usage: %s [-R] file ...\n -H, --more-help\tdisplay ACL format information\n -h, --help\tdisplay this help text\n -R --recursive\trecurse into subdirectories\n -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname); } static void more_help()
The getopt_long() function will return '?' if encounters an option character that was not in optstring. So it's impossible to tell the option '-?' from an unrecognized option. Don't mention it in Usage. Signed-off-by: Yongcheng Yang <yongcheng.yang@gmail.com> --- nfs4_getfacl/nfs4_getfacl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)