Change the way apps open their input and output files
[openssl.git] / apps / opt.c
index 3706739c0337607f2d238b2252bc0cedf206fbdd..c7dcc434e8b2d707c7f2dca2480676c2efe8c172 100644 (file)
 
 /* #define COMPILE_STANDALONE_TEST_DRIVER  */
 #include "apps.h"
-#include <assert.h>
 #include <string.h>
 #if !defined(OPENSSL_SYS_MSDOS)
 # include OPENSSL_UNISTD
 #endif
-#include <unistd.h>
+
 #include <stdlib.h>
 #include <errno.h>
 #include <ctype.h>
@@ -96,11 +95,11 @@ char *opt_progname(const char *argv0)
     /* Strip off trailing nonsense. */
     n = strlen(p);
     if (n > 4 &&
-        (strcmp(&p[n - 4], ".exe") == 0 || strcmp(&p[n - 4], ".EXE") == 0)
+        (strcmp(&p[n - 4], ".exe") == 0 || strcmp(&p[n - 4], ".EXE") == 0))
         n -= 4;
 #if defined(OPENSSL_SYS_NETWARE)
     if (n > 4 &&
-        (strcmp(&p[n - 4], ".nlm") == 0 || strcmp(&p[n - 4], ".NLM") == 0)
+        (strcmp(&p[n - 4], ".nlm") == 0 || strcmp(&p[n - 4], ".NLM") == 0))
         n -= 4;
 #endif
 
@@ -108,7 +107,7 @@ char *opt_progname(const char *argv0)
     if (n > sizeof prog - 1)
         n = sizeof prog - 1;
     for (q = prog, i = 0; i < n; i++, p++)
-        q++ = isupper(*p) ? tolower(*p) : *p;
+        *q++ = isupper(*p) ? tolower(*p) : *p;
     *q = '\0';
     return prog;
 }
@@ -171,7 +170,7 @@ char *opt_init(int ac, char **av, const OPTIONS *o)
     for (; o->name; ++o) {
         const OPTIONS *next;
 #ifndef NDEBUG
-        int i;
+        int duplicated, i;
 #endif
 
         if (o->name == OPT_HELP_STR || o->name == OPT_MORE_STR)
@@ -188,11 +187,12 @@ char *opt_init(int ac, char **av, const OPTIONS *o)
                || i == 'f' || i == 'F');
 
         /* Make sure there are no duplicates. */
-        for (next = o; (++next)->name;) {
+        for (next = o + 1; next->name; ++next) {
             /*
-             * do allow aliases: assert(o->retval != next->retval);
+             * Some compilers inline strcmp and the assert string is too long.
              */
-            assert(strcmp(o->name, next->name) != 0);
+            duplicated = strcmp(o->name, next->name) == 0;
+            assert(!duplicated);
         }
 #endif
         if (o->name[0] == '\0') {
@@ -256,15 +256,11 @@ int opt_format(const char *s, unsigned long flags, int *result)
         break;
     case 'N':
     case 'n':
-        if (strcmp(s, "NSS") == 0 || strcmp(s, "nss") == 0) {
-            if ((flags & OPT_FMT_NSS) == 0)
-                return opt_format_error(s, flags);
-            *result = FORMAT_NSS;
-        } else {
-            if ((flags & OPT_FMT_NETSCAPE) == 0)
-                return opt_format_error(s, flags);
-            *result = FORMAT_NETSCAPE;
-        }
+        if ((flags & OPT_FMT_NSS) == 0)
+            return opt_format_error(s, flags);
+        if (strcmp(s, "NSS") != 0 && strcmp(s, "nss") != 0)
+            return opt_format_error(s, flags);
+        *result = FORMAT_NSS;
         break;
     case 'S':
     case 's':
@@ -547,6 +543,10 @@ int opt_verify(int opt, X509_VERIFY_PARAM *vpm)
         break;
     case OPT_V_NO_ALT_CHAINS:
         X509_VERIFY_PARAM_set_flags(vpm, X509_V_FLAG_NO_ALT_CHAINS);
+       break;
+    case OPT_V_NO_CHECK_TIME:
+        X509_VERIFY_PARAM_set_flags(vpm, X509_V_FLAG_NO_CHECK_TIME);
+       break;
     }
     return 1;
 
@@ -794,7 +794,7 @@ void opt_help(const OPTIONS *list)
         }
 
         /* Pad out prefix */
-        memset(start, ' ', sizeof start - 1);
+        memset(start, ' ', sizeof(start) - 1);
         start[sizeof start - 1] = '\0';
 
         if (o->name == OPT_MORE_STR) {
@@ -820,7 +820,7 @@ void opt_help(const OPTIONS *list)
         if ((int)(p - start) >= MAX_OPT_HELP_WIDTH) {
             *p = '\0';
             BIO_printf(bio_err, "%s\n", start);
-            memset(start, ' ', sizeof start);
+            memset(start, ' ', sizeof(start));
         }
         start[width] = '\0';
         BIO_printf(bio_err, "%s  %s\n", start, help);