aboutsummaryrefslogtreecommitdiff
path: root/openssl-1.1.0h/crypto/err/err_prn.c
diff options
context:
space:
mode:
Diffstat (limited to 'openssl-1.1.0h/crypto/err/err_prn.c')
-rw-r--r--openssl-1.1.0h/crypto/err/err_prn.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/openssl-1.1.0h/crypto/err/err_prn.c b/openssl-1.1.0h/crypto/err/err_prn.c
new file mode 100644
index 0000000..6ae1251
--- /dev/null
+++ b/openssl-1.1.0h/crypto/err/err_prn.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <stdio.h>
+#include "internal/cryptlib.h"
+#include <openssl/lhash.h>
+#include <openssl/crypto.h>
+#include <openssl/buffer.h>
+#include <openssl/err.h>
+
+void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
+ void *u)
+{
+ unsigned long l;
+ char buf[256];
+ char buf2[4096];
+ const char *file, *data;
+ int line, flags;
+ /*
+ * We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
+ * attempt to convert it into something we can print.
+ */
+ union {
+ CRYPTO_THREAD_ID tid;
+ unsigned long ltid;
+ } tid;
+
+ tid.ltid = 0;
+ tid.tid = CRYPTO_THREAD_get_current_id();
+
+ while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
+ ERR_error_string_n(l, buf, sizeof(buf));
+ BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
+ file, line, (flags & ERR_TXT_STRING) ? data : "");
+ if (cb(buf2, strlen(buf2), u) <= 0)
+ break; /* abort outputting the error report */
+ }
+}
+
+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)
+{
+ ERR_print_errors_cb(print_bio, bp);
+}
+
+#ifndef OPENSSL_NO_STDIO
+void ERR_print_errors_fp(FILE *fp)
+{
+ BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
+ if (bio == NULL)
+ return;
+
+ ERR_print_errors_cb(print_bio, bio);
+ BIO_free(bio);
+}
+#endif