diff options
author | 2005-03-25 14:01:37 +0000 | |
---|---|---|
committer | 2005-03-25 14:01:37 +0000 | |
commit | 234c7b4d61af9cf7e51e6455f6180cfc44b44aa7 (patch) | |
tree | c7fcb74e043ed0464a3892de72c13dbef6b36410 /usr.sbin/httpd/src | |
parent | whitespace (diff) | |
download | wireguard-openbsd-234c7b4d61af9cf7e51e6455f6180cfc44b44aa7.tar.xz wireguard-openbsd-234c7b4d61af9cf7e51e6455f6180cfc44b44aa7.zip |
use getopt() for argument list parsing
ok otto@ henning@
Diffstat (limited to 'usr.sbin/httpd/src')
-rw-r--r-- | usr.sbin/httpd/src/support/htpasswd.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/usr.sbin/httpd/src/support/htpasswd.c b/usr.sbin/httpd/src/support/htpasswd.c index f4b6a0d6fb9..23e035532b2 100644 --- a/usr.sbin/httpd/src/support/htpasswd.c +++ b/usr.sbin/httpd/src/support/htpasswd.c @@ -337,7 +337,8 @@ int main(int argc, char *argv[]) int i; int args_left = 2; int tfd; - + int ch; + signal(SIGINT, (void (*)(int)) interrupted); /* @@ -353,50 +354,49 @@ int main(int argc, char *argv[]) * Go through the argument list and pick out any options. They * have to precede any other arguments. */ - for (i = 1; i < argc; i++) { - arg = argv[i]; - if (*arg != '-') { - break; - } - while (*++arg != '\0') { - if (*arg == 'c') { - newfile++; - } - else if (*arg == 'n') { - nofile++; - args_left--; - } - else if (*arg == 'm') { - alg = ALG_APMD5; - } - else if (*arg == 's') { - alg = ALG_APSHA; + while ((ch = getopt(argc, argv, "bcdlnmsp")) != -1) { + switch (ch) { + case 'b': + noninteractive++; + args_left++; + break; + case 'c': + newfile++; + break; + case 'd': + alg = ALG_CRYPT; + break; + case 'l': + alg = ALG_APBLF; + break; + case 'n': + nofile++; + args_left--; + break; + case 'm': + alg = ALG_APMD5; + break; + case 's': + alg = ALG_APSHA; + break; + case 'p': + alg = ALG_PLAIN; + break; + default: + usage(); } - else if (*arg == 'p') { - alg = ALG_PLAIN; - } - else if (*arg == 'd') { - alg = ALG_CRYPT; - } - else if (*arg == 'l') { - alg = ALG_APBLF; - } - else if (*arg == 'b') { - noninteractive++; - args_left++; - } - else { - return usage(); - } - } } + argc -= optind; + argv += optind; + i = argc - args_left; + /* * Make sure we still have exactly the right number of arguments left * (the filename, the username, and possibly the password if -b was * specified). */ - if ((argc - i) != args_left) { + if (argc != args_left) { return usage(); } if (newfile && nofile) { |