X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Ferr%2Ferr_prn.c;h=a0168ac8ed628fd4d511059d68b0bffaebad92ed;hp=19aaa2891fc64d275497dbb6d7887769a886998e;hb=a1644902eb054136591b36cf7b7fc427bc4f52bd;hpb=cf1b7d96647d55e533f779e476e3d4371f40445a diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c index 19aaa2891f..a0168ac8ed 100644 --- a/crypto/err/err_prn.c +++ b/crypto/err/err_prn.c @@ -57,51 +57,58 @@ */ #include +#include "cryptlib.h" #include #include -#include "cryptlib.h" #include #include -#include -#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; + CRYPTO_THREADID cur; - es=CRYPTO_thread_id(); + CRYPTO_THREADID_current(&cur); + es=CRYPTO_THREADID_hash(&cur); 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 : ""); + if (cb(buf2, strlen(buf2), u) <= 0) + break; /* abort outputting the error report */ } } + +#ifndef OPENSSL_NO_FP_API +static int print_fp(const char *str, size_t len, void *fp) + { + BIO bio; + + BIO_set(&bio,BIO_s_file()); + BIO_set_fp(&bio,fp,BIO_NOCLOSE); + + return BIO_printf(&bio, "%s", str); + } +void ERR_print_errors_fp(FILE *fp) + { + ERR_print_errors_cb(print_fp, fp); + } #endif +static int print_bio(const char *str, size_t len, void *bp) + { + return BIO_write((BIO *)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(print_bio, bp); } +