BIO_s_file(3) OpenSSL BIO_s_file(3) NNAAMMEE 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 SSYYNNOOPPSSIISS #include 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) DDEESSCCRRIIPPTTIIOONN _B_I_O___s___f_i_l_e_(_) returns the BIO file method. As its name implies it is a wrapper round the stdio FILE structure and it is a source/sink BIO. Calls to _B_I_O___r_e_a_d_(_) and _B_I_O___w_r_i_t_e_(_) read and write data to the underly- ing stream. _B_I_O___g_e_t_s_(_) and _B_I_O___p_u_t_s_(_) are supported on file BIOs. _B_I_O___f_l_u_s_h_(_) on a file BIO calls the _f_f_l_u_s_h_(_) function on the wrapped stream. _B_I_O___r_e_s_e_t_(_) attempts to change the file pointer to the start of file using fseek(stream, 0, 0). _B_I_O___s_e_e_k_(_) sets the file pointer to position ooffss from start of file using fseek(stream, ofs, 0). _B_I_O___e_o_f_(_) calls _f_e_o_f_(_). Setting the BIO_CLOSE flag calls _f_c_l_o_s_e_(_) on the stream when the BIO is freed. _B_I_O___n_e_w___f_i_l_e_(_) creates a new file BIO with mode mmooddee the meaning of mmooddee is the same as the stdio function _f_o_p_e_n_(_). The BIO_CLOSE flag is set on the returned BIO. _B_I_O___n_e_w___f_p_(_) creates a file BIO wrapping ssttrreeaamm. Flags can be: BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underly- ing stream to text mode, default is binary: this only has any effect under Win32). _B_I_O___s_e_t___f_p_(_) set the fp of a file BIO to ffpp. ffllaaggss has the same meaning as in _B_I_O___n_e_w___f_p_(_), it is a macro. _B_I_O___g_e_t___f_p_(_) retrieves the fp of a file BIO, it is a macro. _B_I_O___s_e_e_k_(_) is a macro that sets the position pointer to ooffffsseett bytes from the start of file. _B_I_O___t_e_l_l_(_) returns the value of the position pointer. _B_I_O___r_e_a_d___f_i_l_e_n_a_m_e_(_), _B_I_O___w_r_i_t_e___f_i_l_e_n_a_m_e_(_), _B_I_O___a_p_p_e_n_d___f_i_l_e_n_a_m_e_(_) and _B_I_O___r_w___f_i_l_e_n_a_m_e_(_) set the file BIO bb to use file nnaammee for reading, writing, append or read write respectively. NNOOTTEESS When wrapping stdout, stdin or stderr the underlying stream should not normally be closed so the BIO_NOCLOSE flag should be set. Because the file BIO calls the underlying stdio functions any quirks in stdio behaviour will be mirrored by the corresponding BIO. On Windows BIO_new_files reserves for the filename argument to be UTF-8 encoded. In other words if you have to make it work in multi- lingual environment, encode file names in UTF-8. EEXXAAMMPPLLEESS File BIO "hello world": BIO *bio_out; bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); BIO_printf(bio_out, "Hello World\n"); Alternative technique: BIO *bio_out; bio_out = BIO_new(BIO_s_file()); if(bio_out == NULL) /* Error ... */ if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */ BIO_printf(bio_out, "Hello World\n"); Write to a file: BIO *out; out = BIO_new_file("filename.txt", "w"); if(!out) /* Error occurred */ BIO_printf(out, "Hello World\n"); BIO_free(out); Alternative technique: BIO *out; out = BIO_new(BIO_s_file()); if(out == NULL) /* Error ... */ if(!BIO_write_filename(out, "filename.txt")) /* Error ... */ BIO_printf(out, "Hello World\n"); BIO_free(out); RREETTUURRNN VVAALLUUEESS _B_I_O___s___f_i_l_e_(_) returns the file BIO method. _B_I_O___n_e_w___f_i_l_e_(_) and _B_I_O___n_e_w___f_p_(_) return a file BIO or NULL if an error occurred. _B_I_O___s_e_t___f_p_(_) and _B_I_O___g_e_t___f_p_(_) return 1 for success or 0 for failure (although the current implementation never return 0). _B_I_O___s_e_e_k_(_) returns the same value as the underlying _f_s_e_e_k_(_) function: 0 for success or -1 for failure. _B_I_O___t_e_l_l_(_) returns the current file position. _B_I_O___r_e_a_d___f_i_l_e_n_a_m_e_(_), _B_I_O___w_r_i_t_e___f_i_l_e_n_a_m_e_(_), _B_I_O___a_p_p_e_n_d___f_i_l_e_n_a_m_e_(_) and _B_I_O___r_w___f_i_l_e_n_a_m_e_(_) return 1 for success or 0 for failure. BBUUGGSS _B_I_O___r_e_s_e_t_(_) and _B_I_O___s_e_e_k_(_) are implemented using _f_s_e_e_k_(_) on the under- lying stream. The return value for _f_s_e_e_k_(_) is 0 for success or -1 if an error occurred this differs from other types of BIO which will typi- cally return 1 for success and a non positive value if an error occurred. SSEEEE AALLSSOO _B_I_O___s_e_e_k(3), _B_I_O___t_e_l_l(3), _B_I_O___r_e_s_e_t(3), _B_I_O___f_l_u_s_h(3), _B_I_O___r_e_a_d(3), _B_I_O___w_r_i_t_e(3), _B_I_O___p_u_t_s(3), _B_I_O___g_e_t_s(3), _B_I_O___p_r_i_n_t_f(3), _B_I_O___s_e_t___c_l_o_s_e(3), _B_I_O___g_e_t___c_l_o_s_e(3) 1.0.1u 2016-09-22 BIO_s_file(3)