1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimBIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp, 6e71b7053SJung-uk KimBIO_read_filename, BIO_write_filename, BIO_append_filename, 7e71b7053SJung-uk KimBIO_rw_filename - FILE bio 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim=head1 SYNOPSIS 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim #include <openssl/bio.h> 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim const BIO_METHOD *BIO_s_file(void); 14e71b7053SJung-uk Kim BIO *BIO_new_file(const char *filename, const char *mode); 15e71b7053SJung-uk Kim BIO *BIO_new_fp(FILE *stream, int flags); 16e71b7053SJung-uk Kim 17e71b7053SJung-uk Kim BIO_set_fp(BIO *b, FILE *fp, int flags); 18e71b7053SJung-uk Kim BIO_get_fp(BIO *b, FILE **fpp); 19e71b7053SJung-uk Kim 20e71b7053SJung-uk Kim int BIO_read_filename(BIO *b, char *name) 21e71b7053SJung-uk Kim int BIO_write_filename(BIO *b, char *name) 22e71b7053SJung-uk Kim int BIO_append_filename(BIO *b, char *name) 23e71b7053SJung-uk Kim int BIO_rw_filename(BIO *b, char *name) 24e71b7053SJung-uk Kim 25e71b7053SJung-uk Kim=head1 DESCRIPTION 26e71b7053SJung-uk Kim 27e71b7053SJung-uk KimBIO_s_file() returns the BIO file method. As its name implies it 28e71b7053SJung-uk Kimis a wrapper round the stdio FILE structure and it is a 29e71b7053SJung-uk Kimsource/sink BIO. 30e71b7053SJung-uk Kim 31e71b7053SJung-uk KimCalls to BIO_read_ex() and BIO_write_ex() read and write data to the 32e71b7053SJung-uk Kimunderlying stream. BIO_gets() and BIO_puts() are supported on file BIOs. 33e71b7053SJung-uk Kim 34e71b7053SJung-uk KimBIO_flush() on a file BIO calls the fflush() function on the wrapped 35e71b7053SJung-uk Kimstream. 36e71b7053SJung-uk Kim 37e71b7053SJung-uk KimBIO_reset() attempts to change the file pointer to the start of file 38e71b7053SJung-uk Kimusing fseek(stream, 0, 0). 39e71b7053SJung-uk Kim 40e71b7053SJung-uk KimBIO_seek() sets the file pointer to position B<ofs> from start of file 41e71b7053SJung-uk Kimusing fseek(stream, ofs, 0). 42e71b7053SJung-uk Kim 43e71b7053SJung-uk KimBIO_eof() calls feof(). 44e71b7053SJung-uk Kim 45e71b7053SJung-uk KimSetting the BIO_CLOSE flag calls fclose() on the stream when the BIO 46e71b7053SJung-uk Kimis freed. 47e71b7053SJung-uk Kim 48e71b7053SJung-uk KimBIO_new_file() creates a new file BIO with mode B<mode> the meaning 49e71b7053SJung-uk Kimof B<mode> is the same as the stdio function fopen(). The BIO_CLOSE 50e71b7053SJung-uk Kimflag is set on the returned BIO. 51e71b7053SJung-uk Kim 52e71b7053SJung-uk KimBIO_new_fp() creates a file BIO wrapping B<stream>. Flags can be: 53e71b7053SJung-uk KimBIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underlying 54e71b7053SJung-uk Kimstream to text mode, default is binary: this only has any effect under 55e71b7053SJung-uk KimWin32). 56e71b7053SJung-uk Kim 57e71b7053SJung-uk KimBIO_set_fp() sets the fp of a file BIO to B<fp>. B<flags> has the same 58e71b7053SJung-uk Kimmeaning as in BIO_new_fp(), it is a macro. 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimBIO_get_fp() retrieves the fp of a file BIO, it is a macro. 61e71b7053SJung-uk Kim 62e71b7053SJung-uk KimBIO_seek() is a macro that sets the position pointer to B<offset> bytes 63e71b7053SJung-uk Kimfrom the start of file. 64e71b7053SJung-uk Kim 65e71b7053SJung-uk KimBIO_tell() returns the value of the position pointer. 66e71b7053SJung-uk Kim 67e71b7053SJung-uk KimBIO_read_filename(), BIO_write_filename(), BIO_append_filename() and 68e71b7053SJung-uk KimBIO_rw_filename() set the file BIO B<b> to use file B<name> for 69e71b7053SJung-uk Kimreading, writing, append or read write respectively. 70e71b7053SJung-uk Kim 71e71b7053SJung-uk Kim=head1 NOTES 72e71b7053SJung-uk Kim 73e71b7053SJung-uk KimWhen wrapping stdout, stdin or stderr the underlying stream should not 74e71b7053SJung-uk Kimnormally be closed so the BIO_NOCLOSE flag should be set. 75e71b7053SJung-uk Kim 76e71b7053SJung-uk KimBecause the file BIO calls the underlying stdio functions any quirks 77e71b7053SJung-uk Kimin stdio behaviour will be mirrored by the corresponding BIO. 78e71b7053SJung-uk Kim 79e71b7053SJung-uk KimOn Windows BIO_new_files reserves for the filename argument to be 80e71b7053SJung-uk KimUTF-8 encoded. In other words if you have to make it work in multi- 81e71b7053SJung-uk Kimlingual environment, encode file names in UTF-8. 82e71b7053SJung-uk Kim 83*610a21fdSJung-uk Kim=head1 RETURN VALUES 84*610a21fdSJung-uk Kim 85*610a21fdSJung-uk KimBIO_s_file() returns the file BIO method. 86*610a21fdSJung-uk Kim 87*610a21fdSJung-uk KimBIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error 88*610a21fdSJung-uk Kimoccurred. 89*610a21fdSJung-uk Kim 90*610a21fdSJung-uk KimBIO_set_fp() and BIO_get_fp() return 1 for success or 0 for failure 91*610a21fdSJung-uk Kim(although the current implementation never return 0). 92*610a21fdSJung-uk Kim 93*610a21fdSJung-uk KimBIO_seek() returns the same value as the underlying fseek() function: 94*610a21fdSJung-uk Kim0 for success or -1 for failure. 95*610a21fdSJung-uk Kim 96*610a21fdSJung-uk KimBIO_tell() returns the current file position. 97*610a21fdSJung-uk Kim 98*610a21fdSJung-uk KimBIO_read_filename(), BIO_write_filename(), BIO_append_filename() and 99*610a21fdSJung-uk KimBIO_rw_filename() return 1 for success or 0 for failure. 100*610a21fdSJung-uk Kim 101e71b7053SJung-uk Kim=head1 EXAMPLES 102e71b7053SJung-uk Kim 103e71b7053SJung-uk KimFile BIO "hello world": 104e71b7053SJung-uk Kim 105e71b7053SJung-uk Kim BIO *bio_out; 106e71b7053SJung-uk Kim 107e71b7053SJung-uk Kim bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); 108e71b7053SJung-uk Kim BIO_printf(bio_out, "Hello World\n"); 109e71b7053SJung-uk Kim 110e71b7053SJung-uk KimAlternative technique: 111e71b7053SJung-uk Kim 112e71b7053SJung-uk Kim BIO *bio_out; 113e71b7053SJung-uk Kim 114e71b7053SJung-uk Kim bio_out = BIO_new(BIO_s_file()); 115e71b7053SJung-uk Kim if (bio_out == NULL) 116e71b7053SJung-uk Kim /* Error */ 117e71b7053SJung-uk Kim if (!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) 118e71b7053SJung-uk Kim /* Error */ 119e71b7053SJung-uk Kim BIO_printf(bio_out, "Hello World\n"); 120e71b7053SJung-uk Kim 121e71b7053SJung-uk KimWrite to a file: 122e71b7053SJung-uk Kim 123e71b7053SJung-uk Kim BIO *out; 124e71b7053SJung-uk Kim 125e71b7053SJung-uk Kim out = BIO_new_file("filename.txt", "w"); 126e71b7053SJung-uk Kim if (!out) 127e71b7053SJung-uk Kim /* Error */ 128e71b7053SJung-uk Kim BIO_printf(out, "Hello World\n"); 129e71b7053SJung-uk Kim BIO_free(out); 130e71b7053SJung-uk Kim 131e71b7053SJung-uk KimAlternative technique: 132e71b7053SJung-uk Kim 133e71b7053SJung-uk Kim BIO *out; 134e71b7053SJung-uk Kim 135e71b7053SJung-uk Kim out = BIO_new(BIO_s_file()); 136e71b7053SJung-uk Kim if (out == NULL) 137e71b7053SJung-uk Kim /* Error */ 138e71b7053SJung-uk Kim if (!BIO_write_filename(out, "filename.txt")) 139e71b7053SJung-uk Kim /* Error */ 140e71b7053SJung-uk Kim BIO_printf(out, "Hello World\n"); 141e71b7053SJung-uk Kim BIO_free(out); 142e71b7053SJung-uk Kim 143e71b7053SJung-uk Kim=head1 BUGS 144e71b7053SJung-uk Kim 145e71b7053SJung-uk KimBIO_reset() and BIO_seek() are implemented using fseek() on the underlying 146e71b7053SJung-uk Kimstream. The return value for fseek() is 0 for success or -1 if an error 147e71b7053SJung-uk Kimoccurred this differs from other types of BIO which will typically return 148e71b7053SJung-uk Kim1 for success and a non positive value if an error occurred. 149e71b7053SJung-uk Kim 150e71b7053SJung-uk Kim=head1 SEE ALSO 151e71b7053SJung-uk Kim 152e71b7053SJung-uk KimL<BIO_seek(3)>, L<BIO_tell(3)>, 153e71b7053SJung-uk KimL<BIO_reset(3)>, L<BIO_flush(3)>, 154e71b7053SJung-uk KimL<BIO_read_ex(3)>, 155e71b7053SJung-uk KimL<BIO_write_ex(3)>, L<BIO_puts(3)>, 156e71b7053SJung-uk KimL<BIO_gets(3)>, L<BIO_printf(3)>, 157e71b7053SJung-uk KimL<BIO_set_close(3)>, L<BIO_get_close(3)> 158e71b7053SJung-uk Kim 159e71b7053SJung-uk Kim=head1 COPYRIGHT 160e71b7053SJung-uk Kim 161*610a21fdSJung-uk KimCopyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. 162e71b7053SJung-uk Kim 163e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 164e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 165e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 166e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 167e71b7053SJung-uk Kim 168e71b7053SJung-uk Kim=cut 169