:: commit f5a08bd55780903d9761509c1c55bd7fa618a487

Kamila Szewczyk <kspalaiologos@gmail.com> — 2022-08-03 19:18

parents: 225edec61f

operr=1: terminate on error; remove redundant check. fix #38

diff --git a/src/main.c b/src/main.c
index 106b4f7..59dcb85 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,8 +56,10 @@ static int getopt_impl(int argc, char * const argv[], const char *optstring) {
         const char *opt = strchr(optstring, arg[optpos]);
         opopt = arg[optpos];
         if (!opt) {
-            if (operr && *optstring != ':')
+            if (operr) {
                 fprintf(stderr, "%s: illegal option: %c\n", argv[0], opopt);
+                exit(1);
+            }
             return '?';
         } else if (opt[1] == ':') {
             if (arg[optpos + 1]) {
@@ -71,10 +73,12 @@ static int getopt_impl(int argc, char * const argv[], const char *optstring) {
                 optpos = 1;
                 return opopt;
             } else {
-                if (operr && *optstring != ':')
+                if (operr) {
                     fprintf(stderr, 
                             "%s: option requires an argument: %c\n", 
                             argv[0], opopt);
+                    exit(1);
+                }
                 return *optstring == ':' ? ':' : '?';
             }
         } else {
tab: 248 wrap: offon