libc: make stdio_impl.h an internal libc header
[unleashed/tickless.git] / lib / libcrypto / man / BIO_s_file.3
blob323763d8380887df90d2acc32f71869b99cf3cb6
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
3 .\"
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2010 The OpenSSL Project.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\"
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
17 .\"    distribution.
18 .\"
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/)"
23 .\"
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.
28 .\"
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.
32 .\"
33 .\" 6. Redistributions of any form whatsoever must retain the following
34 .\"    acknowledgment:
35 .\"    "This product includes software developed by the OpenSSL Project
36 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 .\"
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.
50 .\"
51 .Dd $Mdocdate: December 6 2016 $
52 .Dt BIO_S_FILE 3
53 .Os
54 .Sh NAME
55 .Nm BIO_s_file ,
56 .Nm BIO_new_file ,
57 .Nm BIO_new_fp ,
58 .Nm BIO_set_fp ,
59 .Nm BIO_get_fp ,
60 .Nm BIO_read_filename ,
61 .Nm BIO_write_filename ,
62 .Nm BIO_append_filename ,
63 .Nm BIO_rw_filename
64 .Nd FILE BIO
65 .Sh SYNOPSIS
66 .In openssl/bio.h
67 .Ft BIO_METHOD *
68 .Fo BIO_s_file
69 .Fa void
70 .Fc
71 .Ft BIO *
72 .Fo BIO_new_file
73 .Fa "const char *filename"
74 .Fa "const char *mode"
75 .Fc
76 .Ft BIO *
77 .Fo BIO_new_fp
78 .Fa "FILE *stream"
79 .Fa "int flags"
80 .Fc
81 .Ft long
82 .Fo BIO_set_fp
83 .Fa "BIO *b"
84 .Fa "FILE *fp"
85 .Fa "int flags"
86 .Fc
87 .Ft long
88 .Fo BIO_get_fp
89 .Fa "BIO *b"
90 .Fa "FILE **fpp"
91 .Fc
92 .Ft int
93 .Fo BIO_read_filename
94 .Fa "BIO *b"
95 .Fa "char *name"
96 .Fc
97 .Ft int
98 .Fo BIO_write_filename
99 .Fa "BIO *b"
100 .Fa "char *name"
102 .Ft int
103 .Fo BIO_append_filename
104 .Fa "BIO *b"
105 .Fa "char *name"
107 .Ft int
108 .Fo BIO_rw_filename
109 .Fa "BIO *b"
110 .Fa "char *name"
112 .Sh DESCRIPTION
113 .Fn BIO_s_file
114 returns the BIO file method.
115 As its name implies, it is a wrapper around the stdio
116 .Vt FILE
117 structure and it is a source/sink BIO.
119 Calls to
120 .Xr BIO_read 3
122 .Xr BIO_write 3
123 read and write data to the underlying stream.
124 .Xr BIO_gets 3
126 .Xr BIO_puts 3
127 are supported on file BIOs.
129 .Xr BIO_flush 3
130 on a file BIO calls the
131 .Xr fflush 3
132 function on the wrapped stream.
134 .Xr BIO_reset 3
135 attempts to change the file pointer to the start of file using
136 .Fn fseek stream 0 0 .
138 .Xr BIO_seek 3
139 sets the file pointer to position
140 .Fa ofs
141 from the start of the file using
142 .Fn fseek stream ofs 0 .
144 .Xr BIO_eof 3
145 calls
146 .Xr feof 3 .
148 Setting the
149 .Dv BIO_CLOSE
150 flag calls
151 .Xr fclose 3
152 on the stream when the BIO is freed.
154 .Fn BIO_new_file
155 creates a new file BIO with mode
156 .Fa mode .
157 The meaning of
158 .Fa mode
159 is the same as for the stdio function
160 .Xr fopen 3 .
162 .Dv BIO_CLOSE
163 flag is set on the returned BIO.
165 .Fn BIO_new_fp
166 creates a file BIO wrapping
167 .Fa stream .
168 Flags can be:
169 .Dv BIO_CLOSE , BIO_NOCLOSE Pq the close flag ,
170 .Dv BIO_FP_TEXT
171 (sets the underlying stream to text mode, default is binary:
172 this only has any effect under Win32).
174 .Fn BIO_set_fp
175 set the file pointer of a file BIO to
176 .Fa fp .
177 .Fa flags
178 has the same meaning as in
179 .Fn BIO_new_fp .
180 .Fn BIO_set_fp
181 is a macro.
183 .Fn BIO_get_fp
184 retrieves the file pointer of a file BIO, it is a macro.
186 .Xr BIO_seek 3
187 is a macro that sets the position pointer to
188 .Fa offset
189 bytes from the start of file.
191 .Xr BIO_tell 3
192 returns the value of the position pointer.
194 .Fn BIO_read_filename ,
195 .Fn BIO_write_filename ,
196 .Fn BIO_append_filename ,
198 .Fn BIO_rw_filename
199 set the file BIO
200 .Fa b
201 to use file
202 .Fa name
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
207 .Dv BIO_NOCLOSE
208 flag should be set.
210 Because the file BIO calls the underlying stdio functions, any quirks
211 in stdio behaviour will be mirrored by the corresponding BIO.
213 On Windows,
214 .Fn BIO_new_files
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.
218 .Sh RETURN VALUES
219 .Fn BIO_s_file
220 returns the file BIO method.
222 .Fn BIO_new_file
224 .Fn BIO_new_fp
225 return a file BIO or
226 .Dv NULL
227 if an error occurred.
229 .Fn BIO_set_fp
231 .Fn BIO_get_fp
232 return 1 for success or 0 for failure (although the current
233 implementation never returns 0).
235 .Xr BIO_seek 3
236 returns the same value as the underlying
237 .Xr fseek 3
238 function: 0 for success or -1 for failure.
240 .Xr BIO_tell 3
241 returns the current file position.
243 .Fn BIO_read_filename ,
244 .Fn BIO_write_filename ,
245 .Fn BIO_append_filename ,
247 .Fn BIO_rw_filename
248 return 1 for success or 0 for failure.
249 .Sh EXAMPLES
250 File BIO "hello world":
251 .Bd -literal -offset indent
252 BIO *bio_out;
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
259 BIO *bio_out;
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");
266 Write to a file:
267 .Bd -literal -offset indent
268 BIO *out;
269 out = BIO_new_file("filename.txt", "w");
270 if(!out) /* Error occurred */
271 BIO_printf(out, "Hello World\en");
272 BIO_free(out);
275 Alternative technique:
276 .Bd -literal -offset indent
277 BIO *out;
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");
282 BIO_free(out);
284 .Sh SEE ALSO
285 .Xr BIO_new 3 ,
286 .Xr BIO_read 3 ,
287 .Xr BIO_seek 3
288 .Sh BUGS
289 .Xr BIO_reset 3
291 .Xr BIO_seek 3
292 are implemented using
293 .Xr fseek 3
294 on the underlying stream.
295 The return value for
296 .Xr fseek 3
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.