9 #include <openssl/bio.h>
11 BIO_METHOD * BIO_s_file(void);
12 BIO *BIO_new_file(const char *filename, const char *mode);
13 BIO *BIO_new_fp(FILE *stream, int flags);
15 BIO_set_fp(BIO *b,FILE *fp, int flags);
16 BIO_get_fp(BIO *b,FILE **fpp);
18 BIO_seek(BIO *b,int offset);
21 int BIO_read_filename(BIO *b, char *name)
22 int BIO_write_filename(BIO *b, char *name)
23 int BIO_append_filename(BIO *b, char *name)
24 int BIO_rw_filename(BIO *b, char *name)
28 BIO_s_file() returns the BIO file method. As its name implies it
29 is a wrapper round the stdio FILE structure and it is a
32 Calls to BIO_read() and BIO_write() read and write data to the
33 underlying stream. BIO_gets() and BIO_puts() are supported on file BIOs.
35 BIO_flush() on a file BIO calls the fflush() function on the wrapped
38 BIO_reset() on a file BIO calls fseek() to reset the position indicator
39 to the start of the file.
41 BIO_eof() calls feof().
43 Setting the BIO_CLOSE flag calls fclose() on the stream when the BIO
46 BIO_new_file() creates a new file BIO with mode B<mode> the meaning
47 of B<mode> is the same as the stdio function fopen(). The BIO_CLOSE
48 flag is set on the returned BIO.
50 BIO_new_fp() creates a file BIO wrapping B<stream>. Flags can be:
51 BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underlying
52 stream to text mode, default is binary: this only has any effect under
55 BIO_set_fp() set the fp of a file BIO to B<fp>. B<flags> has the same
56 meaning as in BIO_new_fp(), it is a macro.
58 BIO_get_fp() retrieves the fp of a file BIO, it is a macro.
60 BIO_seek() is a macro that sets the position pointer to B<offset> bytes
61 from the start of file.
63 BIO_tell() returns the value of the position pointer.
65 BIO_read_filename(), BIO_write_filename(), BIO_append_filename() and
66 BIO_rw_filename() set the file BIO B<b> to use file B<name> for
67 reading, writing, append or read write respectively.
71 When wrapping stdout, stdin or stderr the underlying stream should not
72 normally be closed so the BIO_NOCLOSE flag should be set.
74 Because the file BIO calls the underlying stdio functions any quirks
75 in stdio behaviour will be mirrored by the corresponding BIO.
79 File BIO "hello world":
82 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
83 BIO_printf(bio_out, "Hello World\n");
85 Alternative technique:
88 bio_out = BIO_new(BIO_s_file());
89 if(bio_out == NULL) /* Error ... */
90 if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */
91 BIO_printf(bio_out, "Hello World\n");
96 out = BIO_new_file("filename.txt", "w");
97 if(!out) /* Error occurred */
98 BIO_printf(out, "Hello World\n");
101 Alternative technique:
104 out = BIO_new(BIO_s_file());
105 if(out == NULL) /* Error ... */
106 if(!BIO_read_filename(out, "filename.txt")) /* Error ... */
107 BIO_printf(out, "Hello World\n");
112 BIO_s_file() returns the file BIO method.
114 BIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error
117 BIO_set_fp() and BIO_get_fp() return 1 for success or 0 for failure
118 (although the current implementation never return 0).
120 BIO_seek() returns the same value as the underlying fseek() function:
121 0 for success or -1 for failure.
123 BIO_tell() returns the current file position.
125 BIO_read_filename(), BIO_write_filename(), BIO_append_filename() and
126 BIO_rw_filename() return 1 for success or 0 for failure.