summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-05-01 14:35:21 +0200
committerDr. David von Oheimb <dev@ddvo.net>2021-05-05 20:48:20 +0200
commit284076982de7529585c4c13a663203588bff8b12 (patch)
tree07afe26cf4c823f0f20d24b6d95ec32dd5c90820 /apps
parent6c0ac9b99f2b7278a5ec60ef0c29c71e9eb4f40d (diff)
APPS: Slightly extend and improve documentation of the opt_ API
Also remove redundant opt_name() and make names of opt_{i,u}ntmax() consistent. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15111)
Diffstat (limited to 'apps')
-rw-r--r--apps/cmp.c4
-rw-r--r--apps/include/opt.h52
-rw-r--r--apps/lib/apps.c1
-rw-r--r--apps/lib/opt.c29
-rw-r--r--apps/x509.c2
5 files changed, 43 insertions, 45 deletions
diff --git a/apps/cmp.c b/apps/cmp.c
index 51dd971162..14c3a73866 100644
--- a/apps/cmp.c
+++ b/apps/cmp.c
@@ -2188,10 +2188,10 @@ static char *opt_str(void)
if (arg[0] == '\0') {
CMP_warn1("%s option argument is empty string, resetting option",
- opt_name());
+ opt_flag());
arg = NULL;
} else if (arg[0] == '-') {
- CMP_warn1("%s option argument starts with hyphen", opt_name());
+ CMP_warn1("%s option argument starts with hyphen", opt_flag());
}
return arg;
}
diff --git a/apps/include/opt.h b/apps/include/opt.h
index f22e9af05e..a80b6ee43a 100644
--- a/apps/include/opt.h
+++ b/apps/include/opt.h
@@ -342,46 +342,50 @@ typedef struct string_int_pair_st {
#define OPT_PARAMETERS() { OPT_PARAM_STR, 1, '-', "Parameters:\n" }
const char *opt_path_end(const char *filename);
+char *opt_init(int ac, char **av, const OPTIONS * o);
char *opt_progname(const char *argv0);
-char *opt_appname(const char *arg0);
+char *opt_appname(const char *argv0);
char *opt_getprog(void);
-char *opt_init(int ac, char **av, const OPTIONS * o);
-int opt_next(void);
+void opt_help(const OPTIONS * list);
+
void opt_begin(void);
-int opt_format(const char *s, unsigned long flags, int *result);
+int opt_next(void);
+char *opt_flag(void);
+char *opt_arg(void);
+char *opt_unknown(void);
+int opt_cipher(const char *name, EVP_CIPHER **cipherp);
+int opt_cipher_silent(const char *name, EVP_CIPHER **cipherp);
+int opt_md(const char *name, EVP_MD **mdp);
+int opt_md_silent(const char *name, EVP_MD **mdp);
+
int opt_int(const char *arg, int *result);
int opt_int_arg(void);
-int opt_ulong(const char *arg, unsigned long *result);
int opt_long(const char *arg, long *result);
+int opt_ulong(const char *arg, unsigned long *result);
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
defined(INTMAX_MAX) && defined(UINTMAX_MAX) && \
!defined(OPENSSL_NO_INTTYPES_H)
-int opt_imax(const char *arg, intmax_t *result);
-int opt_umax(const char *arg, uintmax_t *result);
+int opt_intmax(const char *arg, intmax_t *result);
+int opt_uintmax(const char *arg, uintmax_t *result);
#else
-# define opt_imax opt_long
-# define opt_umax opt_ulong
+# define opt_intmax opt_long
+# define opt_uintmax opt_ulong
# define intmax_t long
# define uintmax_t unsigned long
#endif
-int opt_pair(const char *arg, const OPT_PAIR * pairs, int *result);
+
+int opt_isdir(const char *name);
+int opt_format(const char *s, unsigned long flags, int *result);
+void print_format_error(int format, unsigned long flags);
+int opt_printf_stderr(const char *fmt, ...);
int opt_string(const char *name, const char **options);
-int opt_cipher(const char *name, EVP_CIPHER **cipherp);
-int opt_cipher_silent(const char *name, EVP_CIPHER **cipherp);
-int opt_md(const char *name, EVP_MD **mdp);
-int opt_md_silent(const char *name, EVP_MD **mdp);
-char *opt_name(void);
-char *opt_arg(void);
-char *opt_flag(void);
-char *opt_unknown(void);
-char **opt_rest(void);
-int opt_num_rest(void);
+int opt_pair(const char *arg, const OPT_PAIR * pairs, int *result);
+
int opt_verify(int i, X509_VERIFY_PARAM *vpm);
int opt_rand(int i);
int opt_provider(int i);
-void opt_help(const OPTIONS * list);
-void print_format_error(int format, unsigned long flags);
-int opt_isdir(const char *name);
-int opt_printf_stderr(const char *fmt, ...);
+
+char **opt_rest(void);
+int opt_num_rest(void);
#endif /* OSSL_APPS_OPT_H */
diff --git a/apps/lib/apps.c b/apps/lib/apps.c
index 81b543ec68..bfd938b555 100644
--- a/apps/lib/apps.c
+++ b/apps/lib/apps.c
@@ -3152,6 +3152,7 @@ void make_uppercase(char *string)
string[i] = toupper((unsigned char)string[i]);
}
+/* This function is defined here due to visibility of bio_err */
int opt_printf_stderr(const char *fmt, ...)
{
va_list ap;
diff --git a/apps/lib/opt.c b/apps/lib/opt.c
index a6b6f7ce4f..4b75b46681 100644
--- a/apps/lib/opt.c
+++ b/apps/lib/opt.c
@@ -36,7 +36,6 @@ const char OPT_PARAM_STR[] = "-P";
static char **argv;
static int argc;
static int opt_index;
-static char *param_name;
static char *arg;
static char *flag;
static char *dunno;
@@ -142,12 +141,12 @@ char *opt_progname(const char *argv0)
}
#endif
-char *opt_appname(const char *arg0)
+char *opt_appname(const char *argv0)
{
size_t len = strlen(prog);
- if (arg0 != NULL)
- BIO_snprintf(prog + len, sizeof(prog) - len - 1, " %s", arg0);
+ if (argv0 != NULL)
+ BIO_snprintf(prog + len, sizeof(prog) - len - 1, " %s", argv0);
return prog;
}
@@ -456,7 +455,7 @@ int opt_int(const char *value, int *result)
return 1;
}
-/* Parse and return a natural number, assuming range has been checked before. */
+/* Parse and return an integer, assuming range has been checked before. */
int opt_int_arg(void)
{
int result = -1;
@@ -515,7 +514,7 @@ int opt_long(const char *value, long *result)
!defined(OPENSSL_NO_INTTYPES_H)
/* Parse an intmax_t, put it into *result; return 0 on failure, else 1. */
-int opt_imax(const char *value, intmax_t *result)
+int opt_intmax(const char *value, intmax_t *result)
{
int oerrno = errno;
intmax_t m;
@@ -537,7 +536,7 @@ int opt_imax(const char *value, intmax_t *result)
}
/* Parse a uintmax_t, put it into *result; return 0 on failure, else 1. */
-int opt_umax(const char *value, uintmax_t *result)
+int opt_uintmax(const char *value, uintmax_t *result)
{
int oerrno = errno;
uintmax_t m;
@@ -654,7 +653,7 @@ int opt_verify(int opt, X509_VERIFY_PARAM *vpm)
X509_VERIFY_PARAM_set_auth_level(vpm, i);
break;
case OPT_V_ATTIME:
- if (!opt_imax(opt_arg(), &t))
+ if (!opt_intmax(opt_arg(), &t))
return 0;
if (t != (time_t)t) {
opt_printf_stderr("%s: epoch time out of range %s\n",
@@ -768,7 +767,7 @@ int opt_next(void)
/* Look at current arg; at end of the list? */
arg = NULL;
- p = param_name = argv[opt_index];
+ p = argv[opt_index];
if (p == NULL)
return 0;
@@ -850,11 +849,11 @@ int opt_next(void)
}
break;
case 'M':
- if (!opt_imax(arg, &imval))
+ if (!opt_intmax(arg, &imval))
return -1;
break;
case 'U':
- if (!opt_umax(arg, &umval))
+ if (!opt_uintmax(arg, &umval))
return -1;
break;
case 'l':
@@ -891,19 +890,13 @@ int opt_next(void)
return -1;
}
-/* Return the name of the most recent flag parameter. */
-char *opt_name(void)
-{
- return param_name;
-}
-
/* Return the most recent flag parameter. */
char *opt_arg(void)
{
return arg;
}
-/* Return the most recent flag. */
+/* Return the most recent flag (option name including the preceding '-'). */
char *opt_flag(void)
{
return flag;
diff --git a/apps/x509.c b/apps/x509.c
index 50453c4b7c..8dffdb47c1 100644
--- a/apps/x509.c
+++ b/apps/x509.c
@@ -544,7 +544,7 @@ int x509_main(int argc, char **argv)
checkend = 1;
{
intmax_t temp = 0;
- if (!opt_imax(opt_arg(), &temp))
+ if (!opt_intmax(opt_arg(), &temp))
goto opthelp;
checkoffset = (time_t)temp;
if ((intmax_t)checkoffset != temp) {