#include <openssl/bio.h>
- const BIO_METHOD * BIO_s_file(void);
+ const BIO_METHOD *BIO_s_file(void);
BIO *BIO_new_file(const char *filename, const char *mode);
BIO *BIO_new_fp(FILE *stream, int flags);
File BIO "hello world":
BIO *bio_out;
+
bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
BIO_printf(bio_out, "Hello World\n");
Alternative technique:
BIO *bio_out;
+
bio_out = BIO_new(BIO_s_file());
- if (bio_out == NULL) /* Error ... */
- if (!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */
+ if (bio_out == NULL)
+ /* Error */
+ if (!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE))
+ /* Error */
BIO_printf(bio_out, "Hello World\n");
Write to a file:
BIO *out;
+
out = BIO_new_file("filename.txt", "w");
- if (!out) /* Error occurred */
+ if (!out)
+ /* Error */
BIO_printf(out, "Hello World\n");
BIO_free(out);
Alternative technique:
BIO *out;
+
out = BIO_new(BIO_s_file());
- if (out == NULL) /* Error ... */
- if (!BIO_write_filename(out, "filename.txt")) /* Error ... */
+ if (out == NULL)
+ /* Error */
+ if (!BIO_write_filename(out, "filename.txt"))
+ /* Error */
BIO_printf(out, "Hello World\n");
BIO_free(out);