1BIO_s_file(3)                       OpenSSL                      BIO_s_file(3)
2
3
4

NAME

6       BIO_s_file, BIO_new_file, BIO_new_fp, BIO_set_fp, BIO_get_fp,
7       BIO_read_filename, BIO_write_filename, BIO_append_filename,
8       BIO_rw_filename - FILE bio
9

SYNOPSIS

11        #include <openssl/bio.h>
12
13        BIO_METHOD *   BIO_s_file(void);
14        BIO *BIO_new_file(const char *filename, const char *mode);
15        BIO *BIO_new_fp(FILE *stream, int flags);
16
17        BIO_set_fp(BIO *b,FILE *fp, int flags);
18        BIO_get_fp(BIO *b,FILE **fpp);
19
20        int BIO_read_filename(BIO *b, char *name)
21        int BIO_write_filename(BIO *b, char *name)
22        int BIO_append_filename(BIO *b, char *name)
23        int BIO_rw_filename(BIO *b, char *name)
24

DESCRIPTION

26       BIO_s_file() returns the BIO file method. As its name implies it is a
27       wrapper round the stdio FILE structure and it is a source/sink BIO.
28
29       Calls to BIO_read() and BIO_write() read and write data to the underly‐
30       ing stream. BIO_gets() and BIO_puts() are supported on file BIOs.
31
32       BIO_flush() on a file BIO calls the fflush() function on the wrapped
33       stream.
34
35       BIO_reset() attempts to change the file pointer to the start of file
36       using fseek(stream, 0, 0).
37
38       BIO_seek() sets the file pointer to position ofs from start of file
39       using fseek(stream, ofs, 0).
40
41       BIO_eof() calls feof().
42
43       Setting the BIO_CLOSE flag calls fclose() on the stream when the BIO is
44       freed.
45
46       BIO_new_file() creates a new file BIO with mode mode the meaning of
47       mode is the same as the stdio function fopen(). The BIO_CLOSE flag is
48       set on the returned BIO.
49
50       BIO_new_fp() creates a file BIO wrapping stream. Flags can be:
51       BIO_CLOSE, BIO_NOCLOSE (the close flag) BIO_FP_TEXT (sets the underly‐
52       ing stream to text mode, default is binary: this only has any effect
53       under Win32).
54
55       BIO_set_fp() set the fp of a file BIO to fp. flags has the same meaning
56       as in BIO_new_fp(), it is a macro.
57
58       BIO_get_fp() retrieves the fp of a file BIO, it is a macro.
59
60       BIO_seek() is a macro that sets the position pointer to offset bytes
61       from the start of file.
62
63       BIO_tell() returns the value of the position pointer.
64
65       BIO_read_filename(), BIO_write_filename(), BIO_append_filename() and
66       BIO_rw_filename() set the file BIO b to use file name for reading,
67       writing, append or read write respectively.
68

NOTES

70       When wrapping stdout, stdin or stderr the underlying stream should not
71       normally be closed so the BIO_NOCLOSE flag should be set.
72
73       Because the file BIO calls the underlying stdio functions any quirks in
74       stdio behaviour will be mirrored by the corresponding BIO.
75

EXAMPLES

77       File BIO "hello world":
78
79        BIO *bio_out;
80        bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
81        BIO_printf(bio_out, "Hello World\n");
82
83       Alternative technique:
84
85        BIO *bio_out;
86        bio_out = BIO_new(BIO_s_file());
87        if(bio_out == NULL) /* Error ... */
88        if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */
89        BIO_printf(bio_out, "Hello World\n");
90
91       Write to a file:
92
93        BIO *out;
94        out = BIO_new_file("filename.txt", "w");
95        if(!out) /* Error occurred */
96        BIO_printf(out, "Hello World\n");
97        BIO_free(out);
98
99       Alternative technique:
100
101        BIO *out;
102        out = BIO_new(BIO_s_file());
103        if(out == NULL) /* Error ... */
104        if(!BIO_write_filename(out, "filename.txt")) /* Error ... */
105        BIO_printf(out, "Hello World\n");
106        BIO_free(out);
107

RETURN VALUES

109       BIO_s_file() returns the file BIO method.
110
111       BIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error
112       occurred.
113
114       BIO_set_fp() and BIO_get_fp() return 1 for success or 0 for failure
115       (although the current implementation never return 0).
116
117       BIO_seek() returns the same value as the underlying fseek() function: 0
118       for success or -1 for failure.
119
120       BIO_tell() returns the current file position.
121
122       BIO_read_filename(), BIO_write_filename(),  BIO_append_filename() and
123       BIO_rw_filename() return 1 for success or 0 for failure.
124

BUGS

126       BIO_reset() and BIO_seek() are implemented using fseek() on the under‐
127       lying stream. The return value for fseek() is 0 for success or -1 if an
128       error occurred this differs from other types of BIO which will typi‐
129       cally return 1 for success and a non positive value if an error
130       occurred.
131

SEE ALSO

133       BIO_seek(3), BIO_tell(3), BIO_reset(3), BIO_flush(3), BIO_read(3),
134       BIO_write(3), BIO_puts(3), BIO_gets(3), BIO_printf(3),
135       BIO_set_close(3), BIO_get_close(3)
136
137
138
1390.9.8b                            2000-09-18                     BIO_s_file(3)
Impressum