summaryrefslogtreecommitdiffstats
path: root/crypto/err
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2001-06-23 15:06:17 +0000
committerRichard Levitte <levitte@openssl.org>2001-06-23 15:06:17 +0000
commit8ada6e7705685be0d97987d31f23e6cf543ef544 (patch)
treecef8ff1e8426809ed8c984ec1495be913f28d731 /crypto/err
parent7f657f342ae81cb010d905e450c06376116a9600 (diff)
New error printing function that gives the possibility to print the
errors through an arbitrary function.
Diffstat (limited to 'crypto/err')
-rw-r--r--crypto/err/err.h2
-rw-r--r--crypto/err/err_prn.c50
2 files changed, 29 insertions, 23 deletions
diff --git a/crypto/err/err.h b/crypto/err/err.h
index 1de4620632..0fb8e02650 100644
--- a/crypto/err/err.h
+++ b/crypto/err/err.h
@@ -249,6 +249,8 @@ void ERR_error_string_n(unsigned long e, char *buf, size_t len);
const char *ERR_lib_error_string(unsigned long e);
const char *ERR_func_error_string(unsigned long e);
const char *ERR_reason_error_string(unsigned long e);
+void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
+ void *u);
#ifndef OPENSSL_NO_FP_API
void ERR_print_errors_fp(FILE *fp);
#endif
diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c
index 19aaa2891f..b5895a4c6f 100644
--- a/crypto/err/err_prn.c
+++ b/crypto/err/err_prn.c
@@ -64,11 +64,12 @@
#include <openssl/err.h>
#include <openssl/crypto.h>
-#ifndef OPENSSL_NO_FP_API
-void ERR_print_errors_fp(FILE *fp)
+void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
+ void *u)
{
unsigned long l;
- char buf[200];
+ char buf[256];
+ char buf2[4096];
const char *file,*data;
int line,flags;
unsigned long es;
@@ -77,31 +78,34 @@ void ERR_print_errors_fp(FILE *fp)
while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
{
ERR_error_string_n(l, buf, sizeof buf);
- fprintf(fp,"%lu:%s:%s:%d:%s\n",es,buf,
- file,line,(flags&ERR_TXT_STRING)?data:"");
+ BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf,
+ file, line, (flags & ERR_TXT_STRING) ? data : "");
+ cb(buf2, strlen(buf2), u);
}
}
+
+#ifndef OPENSSL_NO_FP_API
+static int print_fp(const char *str, size_t len, FILE *fp)
+ {
+ return fprintf(fp, "%s", str);
+ }
+void ERR_print_errors_fp(FILE *fp)
+ {
+ ERR_print_errors_cb(
+ (int (*)(const char *, size_t, void *))print_fp,
+ (void *)fp);
+ }
#endif
+static int print_bio(const char *str, size_t len, BIO *bp)
+ {
+ return BIO_write(bp, str, len);
+ }
void ERR_print_errors(BIO *bp)
{
- unsigned long l;
- char buf[256];
- char buf2[256];
- const char *file,*data;
- int line,flags;
- unsigned long es;
-
- es=CRYPTO_thread_id();
- while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
- {
- ERR_error_string_n(l, buf, sizeof buf);
- sprintf(buf2,"%lu:%s:%s:%d:",es,buf,
- file,line);
- BIO_write(bp,buf2,strlen(buf2));
- if (flags & ERR_TXT_STRING)
- BIO_write(bp,data,strlen(data));
- BIO_write(bp,"\n",1);
- }
+ ERR_print_errors_cb(
+ (int (*)(const char *, size_t, void *))print_bio,
+ (void *)bp);
}
+