| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "BIO_S_FILE 3SSL" |
| 58 |
.TH BIO_S_FILE 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
BIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp, |
| 65 |
BIO_read_filename, BIO_write_filename, BIO_append_filename, |
| 66 |
BIO_rw_filename \- FILE bio |
| 67 |
.SH SYNOPSIS |
| 68 |
.IX Header "SYNOPSIS" |
| 69 |
.Vb 1 |
| 70 |
\& #include <openssl/bio.h> |
| 71 |
\& |
| 72 |
\& const BIO_METHOD *BIO_s_file(void); |
| 73 |
\& BIO *BIO_new_file(const char *filename, const char *mode); |
| 74 |
\& BIO *BIO_new_fp(FILE *stream, int flags); |
| 75 |
\& |
| 76 |
\& BIO_set_fp(BIO *b, FILE *fp, int flags); |
| 77 |
\& BIO_get_fp(BIO *b, FILE **fpp); |
| 78 |
\& |
| 79 |
\& int BIO_read_filename(BIO *b, char *name); |
| 80 |
\& int BIO_write_filename(BIO *b, char *name); |
| 81 |
\& int BIO_append_filename(BIO *b, char *name); |
| 82 |
\& int BIO_rw_filename(BIO *b, char *name); |
| 83 |
.Ve |
| 84 |
.SH DESCRIPTION |
| 85 |
.IX Header "DESCRIPTION" |
| 86 |
\&\fBBIO_s_file()\fR returns the BIO file method. As its name implies it |
| 87 |
is a wrapper round the stdio FILE structure and it is a |
| 88 |
source/sink BIO. |
| 89 |
.PP |
| 90 |
Calls to \fBBIO_read_ex()\fR and \fBBIO_write_ex()\fR read and write data to the |
| 91 |
underlying stream. \fBBIO_gets()\fR and \fBBIO_puts()\fR are supported on file BIOs. |
| 92 |
.PP |
| 93 |
\&\fBBIO_flush()\fR on a file BIO calls the \fBfflush()\fR function on the wrapped |
| 94 |
stream. |
| 95 |
.PP |
| 96 |
\&\fBBIO_reset()\fR attempts to change the file pointer to the start of file |
| 97 |
using fseek(stream, 0, 0). |
| 98 |
.PP |
| 99 |
\&\fBBIO_seek()\fR sets the file pointer to position \fBofs\fR from start of file |
| 100 |
using fseek(stream, ofs, 0). |
| 101 |
.PP |
| 102 |
\&\fBBIO_eof()\fR calls \fBfeof()\fR. |
| 103 |
.PP |
| 104 |
Setting the BIO_CLOSE flag calls \fBfclose()\fR on the stream when the BIO |
| 105 |
is freed. |
| 106 |
.PP |
| 107 |
\&\fBBIO_new_file()\fR creates a new file BIO with mode \fBmode\fR the meaning |
| 108 |
of \fBmode\fR is the same as the stdio function \fBfopen()\fR. The BIO_CLOSE |
| 109 |
flag is set on the returned BIO. |
| 110 |
.PP |
| 111 |
\&\fBBIO_new_fp()\fR creates a file BIO wrapping \fBstream\fR. Flags can be: |
| 112 |
BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underlying |
| 113 |
stream to text mode, default is binary: this only has any effect under |
| 114 |
Win32). |
| 115 |
.PP |
| 116 |
\&\fBBIO_set_fp()\fR sets the fp of a file BIO to \fBfp\fR. \fBflags\fR has the same |
| 117 |
meaning as in \fBBIO_new_fp()\fR, it is a macro. |
| 118 |
.PP |
| 119 |
\&\fBBIO_get_fp()\fR retrieves the fp of a file BIO, it is a macro. |
| 120 |
.PP |
| 121 |
\&\fBBIO_seek()\fR is a macro that sets the position pointer to \fBoffset\fR bytes |
| 122 |
from the start of file. |
| 123 |
.PP |
| 124 |
\&\fBBIO_tell()\fR returns the value of the position pointer. |
| 125 |
.PP |
| 126 |
\&\fBBIO_read_filename()\fR, \fBBIO_write_filename()\fR, \fBBIO_append_filename()\fR and |
| 127 |
\&\fBBIO_rw_filename()\fR set the file BIO \fBb\fR to use file \fBname\fR for |
| 128 |
reading, writing, append or read write respectively. |
| 129 |
.SH NOTES |
| 130 |
.IX Header "NOTES" |
| 131 |
When wrapping stdout, stdin or stderr the underlying stream should not |
| 132 |
normally be closed so the BIO_NOCLOSE flag should be set. |
| 133 |
.PP |
| 134 |
Because the file BIO calls the underlying stdio functions any quirks |
| 135 |
in stdio behaviour will be mirrored by the corresponding BIO. |
| 136 |
.PP |
| 137 |
On Windows BIO_new_files reserves for the filename argument to be |
| 138 |
UTF\-8 encoded. In other words if you have to make it work in multi\- |
| 139 |
lingual environment, encode filenames in UTF\-8. |
| 140 |
.SH "RETURN VALUES" |
| 141 |
.IX Header "RETURN VALUES" |
| 142 |
\&\fBBIO_s_file()\fR returns the file BIO method. |
| 143 |
.PP |
| 144 |
\&\fBBIO_new_file()\fR and \fBBIO_new_fp()\fR return a file BIO or NULL if an error |
| 145 |
occurred. |
| 146 |
.PP |
| 147 |
\&\fBBIO_set_fp()\fR and \fBBIO_get_fp()\fR return 1 for success or <=0 for failure |
| 148 |
(although the current implementation never return 0). |
| 149 |
.PP |
| 150 |
\&\fBBIO_seek()\fR returns 0 for success or negative values for failure. |
| 151 |
.PP |
| 152 |
\&\fBBIO_tell()\fR returns the current file position or negative values for failure. |
| 153 |
.PP |
| 154 |
\&\fBBIO_read_filename()\fR, \fBBIO_write_filename()\fR, \fBBIO_append_filename()\fR and |
| 155 |
\&\fBBIO_rw_filename()\fR return 1 for success or <=0 for failure. An error is also |
| 156 |
returned if the file does not exist. |
| 157 |
.SH EXAMPLES |
| 158 |
.IX Header "EXAMPLES" |
| 159 |
File BIO "hello world": |
| 160 |
.PP |
| 161 |
.Vb 1 |
| 162 |
\& BIO *bio_out; |
| 163 |
\& |
| 164 |
\& bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); |
| 165 |
\& BIO_printf(bio_out, "Hello World\en"); |
| 166 |
.Ve |
| 167 |
.PP |
| 168 |
Alternative technique: |
| 169 |
.PP |
| 170 |
.Vb 1 |
| 171 |
\& BIO *bio_out; |
| 172 |
\& |
| 173 |
\& bio_out = BIO_new(BIO_s_file()); |
| 174 |
\& if (bio_out == NULL) |
| 175 |
\& /* Error */ |
| 176 |
\& if (BIO_set_fp(bio_out, stdout, BIO_NOCLOSE) <= 0) |
| 177 |
\& /* Error */ |
| 178 |
\& BIO_printf(bio_out, "Hello World\en"); |
| 179 |
.Ve |
| 180 |
.PP |
| 181 |
Write to a file: |
| 182 |
.PP |
| 183 |
.Vb 1 |
| 184 |
\& BIO *out; |
| 185 |
\& |
| 186 |
\& out = BIO_new_file("filename.txt", "w"); |
| 187 |
\& if (!out) |
| 188 |
\& /* Error */ |
| 189 |
\& BIO_printf(out, "Hello World\en"); |
| 190 |
\& BIO_free(out); |
| 191 |
.Ve |
| 192 |
.PP |
| 193 |
Alternative technique: |
| 194 |
.PP |
| 195 |
.Vb 1 |
| 196 |
\& BIO *out; |
| 197 |
\& |
| 198 |
\& out = BIO_new(BIO_s_file()); |
| 199 |
\& if (out == NULL) |
| 200 |
\& /* Error */ |
| 201 |
\& if (BIO_write_filename(out, "filename.txt") <= 0) |
| 202 |
\& /* Error */ |
| 203 |
\& BIO_printf(out, "Hello World\en"); |
| 204 |
\& BIO_free(out); |
| 205 |
.Ve |
| 206 |
.SH BUGS |
| 207 |
.IX Header "BUGS" |
| 208 |
\&\fBBIO_reset()\fR and \fBBIO_seek()\fR are implemented using \fBfseek()\fR on the underlying |
| 209 |
stream. The return value for \fBfseek()\fR is 0 for success or \-1 if an error |
| 210 |
occurred this differs from other types of BIO which will typically return |
| 211 |
1 for success and a non positive value if an error occurred. |
| 212 |
.SH "SEE ALSO" |
| 213 |
.IX Header "SEE ALSO" |
| 214 |
\&\fBBIO_seek\fR\|(3), \fBBIO_tell\fR\|(3), |
| 215 |
\&\fBBIO_reset\fR\|(3), \fBBIO_flush\fR\|(3), |
| 216 |
\&\fBBIO_read_ex\fR\|(3), |
| 217 |
\&\fBBIO_write_ex\fR\|(3), \fBBIO_puts\fR\|(3), |
| 218 |
\&\fBBIO_gets\fR\|(3), \fBBIO_printf\fR\|(3), |
| 219 |
\&\fBBIO_set_close\fR\|(3), \fBBIO_get_close\fR\|(3) |
| 220 |
.SH COPYRIGHT |
| 221 |
.IX Header "COPYRIGHT" |
| 222 |
Copyright 2000\-2020 The OpenSSL Project Authors. All Rights Reserved. |
| 223 |
.PP |
| 224 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 225 |
this file except in compliance with the License. You can obtain a copy |
| 226 |
in the file LICENSE in the source distribution or at |
| 227 |
<https://www.openssl.org/source/license.html>. |