Missing pathname argument can only be checked after options are
parsed. Earlier for example 'namei -l' print nothing and was
successful.
The option parsing is changed to be less POSIXLY_CORRECT and
continue if nonoption argument is found, which allows users to
define options and arguments in the order they prefer.
Unknown short options, which earlier matched case '?' that was
help option alias, are now made to indicate failure in return
value.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
int
main(int argc, char **argv)
{
- extern int optind;
int c;
int rc = EXIT_SUCCESS;
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- if (argc < 2)
- usage(EXIT_FAILURE);
-
- while ((c = getopt_long(argc, argv, "+h?Vlmnovx", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "hVlmnovx", longopts, NULL)) != -1) {
switch(c) {
case 'h':
- case '?':
usage(EXIT_SUCCESS);
break;
case 'V':
break;
case 'v':
flags |= NAMEI_VERTICAL;
+ break;
+ default:
+ usage(EXIT_FAILURE);
}
}
+ if (optind == argc) {
+ warnx(_("pathname argument is missing"));
+ usage(EXIT_FAILURE);
+ }
+
for(; optind < argc; optind++) {
char *path = argv[optind];
struct namei *nm = NULL;