summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2014-06-11 15:08:44 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2014-06-11 15:08:44 +0000
commit1d430b04e7683520244df7ba1086d1588dcc66a3 (patch)
treee24e03144c7cce9b0dcefaffea4d308d418b9a78
parenta49af1d6fa7f5f7af8a8ea1cc2ce26bd9e41ae91 (diff)
Provide support for non-funopen systems.
ok beck
-rw-r--r--lib/libcrypto/bio/b_print.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/libcrypto/bio/b_print.c b/lib/libcrypto/bio/b_print.c
index 3a8fdcc8213..a790bb0b7da 100644
--- a/lib/libcrypto/bio/b_print.c
+++ b/lib/libcrypto/bio/b_print.c
@@ -1,14 +1,8 @@
-/* $OpenBSD: b_print.c,v 1.22 2014/04/21 11:18:34 deraadt Exp $ */
+/* $OpenBSD: b_print.c,v 1.23 2014/06/11 15:08:43 deraadt Exp $ */
/* Theo de Raadt places this file in the public domain. */
#include <openssl/bio.h>
-static int
-_BIO_write(void *cookie, const char *buf, int nbytes)
-{
- return BIO_write(cookie, buf, nbytes);
-}
-
int
BIO_printf(BIO *bio, const char *format, ...)
{
@@ -21,11 +15,18 @@ BIO_printf(BIO *bio, const char *format, ...)
return (ret);
}
+#ifdef HAVE_FUNOPEN
+static int
+_BIO_write(void *cookie, const char *buf, int nbytes)
+{
+ return BIO_write(cookie, buf, nbytes);
+}
+
int
BIO_vprintf(BIO *bio, const char *format, va_list args)
{
- FILE *fp;
int ret;
+ FILE *fp;
fp = funopen(bio, NULL, &_BIO_write, NULL, NULL);
if (fp == NULL) {
@@ -38,6 +39,27 @@ fail:
return (ret);
}
+#else /* !HAVE_FUNOPEN */
+
+int
+BIO_vprintf(BIO *bio, const char *format, va_list args)
+{
+ int ret;
+ char *buf = NULL;
+
+ ret = vasprintf(&buf, format, args);
+ if (buf == NULL) {
+ ret = -1
+ goto fail;
+ }
+ BIO_write(bio, buf, ret);
+ free(buf);
+fail:
+ return (ret);
+}
+
+#endif /* HAVE_FUNOPEN */
+
/*
* BIO_snprintf and BIO_vsnprintf return -1 for overflow,
* due to the history of this API. Justification: