xref: /freebsd/secure/lib/libcrypto/man/man3/BIO_s_file.3 (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40)

Standard preamble:
========================================================================
..
..
.. Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.

If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.

Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF
Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================

Title "BIO_S_FILE 3"
BIO_S_FILE 3 "2023-05-30" "3.0.9" "OpenSSL"
For nroff, turn off justification. Always turn off hyphenation; it makes
way too many mistakes in technical documents.
"NAME"
BIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp, BIO_read_filename, BIO_write_filename, BIO_append_filename, BIO_rw_filename - FILE bio
"SYNOPSIS"
Header "SYNOPSIS" .Vb 1 #include <openssl/bio.h> \& 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); \& BIO_set_fp(BIO *b, FILE *fp, int flags); BIO_get_fp(BIO *b, FILE **fpp); \& int BIO_read_filename(BIO *b, char *name); int BIO_write_filename(BIO *b, char *name); int BIO_append_filename(BIO *b, char *name); int BIO_rw_filename(BIO *b, char *name); .Ve
"DESCRIPTION"
Header "DESCRIPTION" \fBBIO_s_file() returns the \s-1BIO\s0 file method. As its name implies it is a wrapper round the stdio \s-1FILE\s0 structure and it is a source/sink \s-1BIO.\s0

Calls to BIO_read_ex() and BIO_write_ex() read and write data to the underlying stream. BIO_gets() and BIO_puts() are supported on file BIOs.

\fBBIO_flush() on a file \s-1BIO\s0 calls the fflush() function on the wrapped stream.

\fBBIO_reset() attempts to change the file pointer to the start of file using fseek(stream, 0, 0).

\fBBIO_seek() sets the file pointer to position ofs from start of file using fseek(stream, ofs, 0).

\fBBIO_eof() calls feof().

Setting the \s-1BIO_CLOSE\s0 flag calls fclose() on the stream when the \s-1BIO\s0 is freed.

\fBBIO_new_file() creates a new file \s-1BIO\s0 with mode mode the meaning of mode is the same as the stdio function fopen(). The \s-1BIO_CLOSE\s0 flag is set on the returned \s-1BIO.\s0

\fBBIO_new_fp() creates a file \s-1BIO\s0 wrapping stream. Flags can be: \s-1BIO_CLOSE, BIO_NOCLOSE\s0 (the close flag) \s-1BIO_FP_TEXT\s0 (sets the underlying stream to text mode, default is binary: this only has any effect under Win32).

\fBBIO_set_fp() sets the fp of a file \s-1BIO\s0 to fp. flags has the same meaning as in BIO_new_fp(), it is a macro.

\fBBIO_get_fp() retrieves the fp of a file \s-1BIO,\s0 it is a macro.

\fBBIO_seek() is a macro that sets the position pointer to offset bytes from the start of file.

\fBBIO_tell() returns the value of the position pointer.

\fBBIO_read_filename(), BIO_write_filename(), BIO_append_filename() and \fBBIO_rw_filename() set the file \s-1BIO\s0 b to use file name for reading, writing, append or read write respectively.

"NOTES"
Header "NOTES" When wrapping stdout, stdin or stderr the underlying stream should not normally be closed so the \s-1BIO_NOCLOSE\s0 flag should be set.

Because the file \s-1BIO\s0 calls the underlying stdio functions any quirks in stdio behaviour will be mirrored by the corresponding \s-1BIO.\s0

On Windows BIO_new_files reserves for the filename argument to be \s-1UTF-8\s0 encoded. In other words if you have to make it work in multi- lingual environment, encode filenames in \s-1UTF-8.\s0

"RETURN VALUES"
Header "RETURN VALUES" \fBBIO_s_file() returns the file \s-1BIO\s0 method.

\fBBIO_new_file() and BIO_new_fp() return a file \s-1BIO\s0 or \s-1NULL\s0 if an error occurred.

\fBBIO_set_fp() and BIO_get_fp() return 1 for success or <=0 for failure (although the current implementation never return 0).

\fBBIO_seek() returns 0 for success or negative values for failure.

\fBBIO_tell() returns the current file position or negative values for failure.

\fBBIO_read_filename(), BIO_write_filename(), BIO_append_filename() and \fBBIO_rw_filename() return 1 for success or <=0 for failure.

"EXAMPLES"
Header "EXAMPLES" File \s-1BIO\s0 \*(L"hello world\*(R":

.Vb 1 BIO *bio_out; \& bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); BIO_printf(bio_out, "Hello World\en"); .Ve

Alternative technique:

.Vb 1 BIO *bio_out; \& bio_out = BIO_new(BIO_s_file()); if (bio_out == NULL) /* Error */ if (BIO_set_fp(bio_out, stdout, BIO_NOCLOSE) <= 0) /* Error */ BIO_printf(bio_out, "Hello World\en"); .Ve

Write to a file:

.Vb 1 BIO *out; \& out = BIO_new_file("filename.txt", "w"); if (!out) /* Error */ BIO_printf(out, "Hello World\en"); BIO_free(out); .Ve

Alternative technique:

.Vb 1 BIO *out; \& out = BIO_new(BIO_s_file()); if (out == NULL) /* Error */ if (BIO_write_filename(out, "filename.txt") <= 0) /* Error */ BIO_printf(out, "Hello World\en"); BIO_free(out); .Ve

"BUGS"
Header "BUGS" \fBBIO_reset() and BIO_seek() are implemented using fseek() on the underlying stream. The return value for fseek() is 0 for success or -1 if an error occurred this differs from other types of \s-1BIO\s0 which will typically return 1 for success and a non positive value if an error occurred.
"SEE ALSO"
Header "SEE ALSO" \fBBIO_seek\|(3), BIO_tell\|(3), \fBBIO_reset\|(3), BIO_flush\|(3), \fBBIO_read_ex\|(3), \fBBIO_write_ex\|(3), BIO_puts\|(3), \fBBIO_gets\|(3), BIO_printf\|(3), \fBBIO_set_close\|(3), BIO_get_close\|(3)
"COPYRIGHT"
Header "COPYRIGHT" Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.