summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/usr.bin/openssl/errstr.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/usr.bin/openssl/errstr.c b/src/usr.bin/openssl/errstr.c
index 163da2e5b3..16d3832c88 100644
--- a/src/usr.bin/openssl/errstr.c
+++ b/src/usr.bin/openssl/errstr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: errstr.c,v 1.1 2014/08/26 17:47:24 jsing Exp $ */ 1/* $OpenBSD: errstr.c,v 1.2 2015/04/13 15:02:23 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -67,6 +67,27 @@
67#include <openssl/lhash.h> 67#include <openssl/lhash.h>
68#include <openssl/ssl.h> 68#include <openssl/ssl.h>
69 69
70struct {
71 int stats;
72} errstr_config;
73
74struct option errstr_options[] = {
75 {
76 .name = "stats",
77 .desc = "Print debugging statistics for the hash table",
78 .type = OPTION_FLAG,
79 .opt.flag = &errstr_config.stats,
80 },
81 { NULL },
82};
83
84static void
85errstr_usage()
86{
87 fprintf(stderr, "usage: errstr [-stats] errno ...\n");
88 options_usage(errstr_options);
89}
90
70int errstr_main(int, char **); 91int errstr_main(int, char **);
71 92
72int 93int
@@ -75,8 +96,16 @@ errstr_main(int argc, char **argv)
75 int i, ret = 0; 96 int i, ret = 0;
76 char buf[256]; 97 char buf[256];
77 unsigned long l; 98 unsigned long l;
99 int argsused;
78 100
79 if ((argc > 1) && (strcmp(argv[1], "-stats") == 0)) { 101 memset(&errstr_config, 0, sizeof(errstr_config));
102
103 if (options_parse(argc, argv, errstr_options, NULL, &argsused) != 0) {
104 errstr_usage();
105 return (1);
106 }
107
108 if (errstr_config.stats) {
80 BIO *out = NULL; 109 BIO *out = NULL;
81 110
82 out = BIO_new(BIO_s_file()); 111 out = BIO_new(BIO_s_file());
@@ -90,16 +119,15 @@ errstr_main(int argc, char **argv)
90 } 119 }
91 if (out != NULL) 120 if (out != NULL)
92 BIO_free_all(out); 121 BIO_free_all(out);
93 argc--;
94 argv++;
95 } 122 }
96 for (i = 1; i < argc; i++) { 123
124 for (i = argsused; i < argc; i++) {
97 if (sscanf(argv[i], "%lx", &l)) { 125 if (sscanf(argv[i], "%lx", &l)) {
98 ERR_error_string_n(l, buf, sizeof buf); 126 ERR_error_string_n(l, buf, sizeof buf);
99 printf("%s\n", buf); 127 printf("%s\n", buf);
100 } else { 128 } else {
101 printf("%s: bad error code\n", argv[i]); 129 printf("%s: bad error code\n", argv[i]);
102 printf("usage: errstr [-stats] <errno> ...\n"); 130 errstr_usage();
103 ret++; 131 ret++;
104 } 132 }
105 } 133 }