]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/err/err_prn.c
Consistent formatting for sizeof(foo)
[thirdparty/openssl.git] / crypto / err / err_prn.c
CommitLineData
aa6bb135 1/*
f32b0abe 2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
d02b48c6 3 *
aa6bb135
RS
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
d02b48c6
RE
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
ec577822 12#include <openssl/crypto.h>
ec577822
BM
13#include <openssl/buffer.h>
14#include <openssl/err.h>
d02b48c6 15
0f113f3e
MC
16void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
17 void *u)
18{
19 unsigned long l;
20 char buf[256];
21 char buf2[4096];
22 const char *file, *data;
23 int line, flags;
2e52e7df
MC
24 /*
25 * We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
26 * attempt to convert it into something we can print.
27 */
28 union {
29 CRYPTO_THREAD_ID tid;
30 unsigned long ltid;
31 } tid;
32
33 tid.ltid = 0;
34 tid.tid = CRYPTO_THREAD_get_current_id();
d02b48c6 35
0f113f3e 36 while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
cbe29648 37 ERR_error_string_n(l, buf, sizeof(buf));
2e52e7df 38 BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
0f113f3e
MC
39 file, line, (flags & ERR_TXT_STRING) ? data : "");
40 if (cb(buf2, strlen(buf2), u) <= 0)
41 break; /* abort outputting the error report */
42 }
43}
8ada6e77 44
6a184a60 45static int print_bio(const char *str, size_t len, void *bp)
0f113f3e
MC
46{
47 return BIO_write((BIO *)bp, str, len);
48}
d02b48c6 49
0f113f3e
MC
50void ERR_print_errors(BIO *bp)
51{
52 ERR_print_errors_cb(print_bio, bp);
53}
1a50b813
F
54
55#ifndef OPENSSL_NO_STDIO
56void ERR_print_errors_fp(FILE *fp)
57{
58 BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
59 if (bio == NULL)
60 return;
61
62 ERR_print_errors_cb(print_bio, bio);
63 BIO_free(bio);
64}
65#endif