1 .\" $OpenBSD: BIO_s_file.3,v 1.5 2016/12/06 14:45:08 schwarze Exp $
2 .\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2010 The OpenSSL Project. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in
16 .\" the documentation and/or other materials provided with the
19 .\" 3. All advertising materials mentioning features or use of this
20 .\" software must display the following acknowledgment:
21 .\" "This product includes software developed by the OpenSSL Project
22 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\" endorse or promote products derived from this software without
26 .\" prior written permission. For written permission, please contact
27 .\" openssl-core@openssl.org.
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\" nor may "OpenSSL" appear in their names without prior written
31 .\" permission of the OpenSSL Project.
33 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\" "This product includes software developed by the OpenSSL Project
36 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .Dd $Mdocdate: December 6 2016 $
60 .Nm BIO_read_filename ,
61 .Nm BIO_write_filename ,
62 .Nm BIO_append_filename ,
73 .Fa "const char *filename"
74 .Fa "const char *mode"
98 .Fo BIO_write_filename
103 .Fo BIO_append_filename
114 returns the BIO file method.
115 As its name implies, it is a wrapper around the stdio
117 structure and it is a source/sink BIO.
123 read and write data to the underlying stream.
127 are supported on file BIOs.
130 on a file BIO calls the
132 function on the wrapped stream.
135 attempts to change the file pointer to the start of file using
136 .Fn fseek stream 0 0 .
139 sets the file pointer to position
141 from the start of the file using
142 .Fn fseek stream ofs 0 .
152 on the stream when the BIO is freed.
155 creates a new file BIO with mode
159 is the same as for the stdio function
163 flag is set on the returned BIO.
166 creates a file BIO wrapping
169 .Dv BIO_CLOSE , BIO_NOCLOSE Pq the close flag ,
171 (sets the underlying stream to text mode, default is binary:
172 this only has any effect under Win32).
175 set the file pointer of a file BIO to
178 has the same meaning as in
184 retrieves the file pointer of a file BIO, it is a macro.
187 is a macro that sets the position pointer to
189 bytes from the start of file.
192 returns the value of the position pointer.
194 .Fn BIO_read_filename ,
195 .Fn BIO_write_filename ,
196 .Fn BIO_append_filename ,
203 for reading, writing, append or read write respectively.
205 When wrapping stdout, stdin, or stderr, the underlying stream
206 should not normally be closed, so the
210 Because the file BIO calls the underlying stdio functions, any quirks
211 in stdio behaviour will be mirrored by the corresponding BIO.
215 reserves for the filename argument to be UTF-8 encoded.
216 In other words, if you have to make it work in a multi-lingual
217 environment, encode file names in UTF-8.
220 returns the file BIO method.
227 if an error occurred.
232 return 1 for success or 0 for failure (although the current
233 implementation never returns 0).
236 returns the same value as the underlying
238 function: 0 for success or -1 for failure.
241 returns the current file position.
243 .Fn BIO_read_filename ,
244 .Fn BIO_write_filename ,
245 .Fn BIO_append_filename ,
248 return 1 for success or 0 for failure.
250 File BIO "hello world":
251 .Bd -literal -offset indent
253 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
254 BIO_printf(bio_out, "Hello World\en");
257 Alternative technique:
258 .Bd -literal -offset indent
260 bio_out = BIO_new(BIO_s_file());
261 if(bio_out == NULL) /* Error ... */
262 if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */
263 BIO_printf(bio_out, "Hello World\en");
267 .Bd -literal -offset indent
269 out = BIO_new_file("filename.txt", "w");
270 if(!out) /* Error occurred */
271 BIO_printf(out, "Hello World\en");
275 Alternative technique:
276 .Bd -literal -offset indent
278 out = BIO_new(BIO_s_file());
279 if(out == NULL) /* Error ... */
280 if(!BIO_write_filename(out, "filename.txt")) /* Error ... */
281 BIO_printf(out, "Hello World\en");
292 are implemented using
294 on the underlying stream.
297 is 0 for success or -1 if an error occurred.
298 This differs from other types of BIO which will typically return
299 1 for success and a non-positive value if an error occurred.