Matthew Martin <[email protected]> writes:
> As far as I can tell the only thing gained from using getopt is handling
> vipw --
> as vipw takes no flags or arguments, is not intended for non-interactive
> use, and is not POSIX, I don't see a reason -- should be handled.
I don't see a reason not to handle -- as in other utilities. Standard
getopt(3) handling in all programs give a consistent user experience.
I don't think this code costs much.
> If
> anyone prefers proper handling of -- perhaps
> if (!( argc == 1 || (argc == 2 && strcmp(argv[1], "--") == 0)))
>
> Also kill a needless include.
I have committed this hunk, thanks.
> - Matthew Martin
>
> diff --git vipw.c vipw.c
> index e9595b02198..88a741f1c15 100644
> --- vipw.c
> +++ vipw.c
> @@ -37,7 +37,6 @@
> #include <pwd.h>
> #include <stdio.h>
> #include <stdlib.h>
> -#include <string.h>
> #include <unistd.h>
> #include <util.h>
>
> @@ -49,18 +48,8 @@ main(int argc, char *argv[])
> {
> int pfd, tfd;
> struct stat begin, end;
> - int ch;
>
> - while ((ch = getopt(argc, argv, "")) != -1) {
> - switch (ch) {
> - default:
> - usage();
> - }
> - }
> - argc -= optind;
> - argv += optind;
> -
> - if (argc != 0)
> + if (argc != 1)
> usage();
>
> if (pledge("stdio rpath wpath cpath fattr proc exec", NULL) == -1)
>
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE