From b9b725514027a560daae1c5518c700360b5764bc Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Wed, 11 Jun 2014 15:08:43 +0000 Subject: Provide support for non-funopen systems. ok beck --- src/lib/libcrypto/bio/b_print.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src/lib/libcrypto/bio/b_print.c') diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index 3a8fdcc821..a790bb0b7d 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/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 -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: -- cgit v1.2.3-55-g6feb