2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/lhash.h>
13 #include <openssl/crypto.h>
14 #include <openssl/buffer.h>
15 #include <openssl/err.h>
17 void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
23 const char *file, *data;
26 * We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
27 * attempt to convert it into something we can print.
35 tid.tid = CRYPTO_THREAD_get_current_id();
37 while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
38 ERR_error_string_n(l, buf, sizeof buf);
39 BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
40 file, line, (flags & ERR_TXT_STRING) ? data : "");
41 if (cb(buf2, strlen(buf2), u) <= 0)
42 break; /* abort outputting the error report */
46 static int print_bio(const char *str, size_t len, void *bp)
48 return BIO_write((BIO *)bp, str, len);
51 void ERR_print_errors(BIO *bp)
53 ERR_print_errors_cb(print_bio, bp);
56 #ifndef OPENSSL_NO_STDIO
57 void ERR_print_errors_fp(FILE *fp)
59 BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
63 ERR_print_errors_cb(print_bio, bio);