BIO_s_fd() manual page.
[openssl.git] / doc / crypto / BIO_s_file.pod
1 =pod
2
3 =head1 NAME
4
5         BIO_s_file - FILE bio.
6
7 =head1 SYNOPSIS
8
9  #include <openssl/bio.h>
10
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);
14
15  BIO_set_fp(BIO *b,FILE *fp, int flags);
16  BIO_get_fp(BIO *b,FILE **fpp);
17
18  BIO_seek(BIO *b,int offset);
19  int BIO_tell(BIO *b);
20
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)
25
26 =head1 DESCRIPTION
27
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
30 source/sink BIO.
31
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.
34
35 BIO_flush() on a file BIO calls the fflush() function on the wrapped
36 stream.
37
38 BIO_reset() on a file BIO calls fseek() to reset the position indicator
39 to the start of the file.
40
41 BIO_eof() calls feof().
42
43 Setting the BIO_CLOSE flag calls fclose() on the stream when the BIO
44 is freed.
45
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.
49
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
53 Win32).
54
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.
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 B<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<b> to use file B<name> for
67 reading, writing, append or read write respectively.
68
69 =head1 NOTES
70
71 When wrapping stdout, stdin or stderr the underlying stream should not
72 normally be closed so the BIO_NOCLOSE flag should be set.
73
74 Because the file BIO calls the underlying stdio functions any quirks
75 in stdio behaviour will be mirrored by the corresponding BIO.
76
77 =head1 EXAMPLES
78
79 File BIO "hello world":
80
81  BIO *bio_out;
82  bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
83  BIO_printf(bio_out, "Hello World\n");
84
85 Alternative technique:
86
87  BIO *bio_out;
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");
92
93 Write to a file:
94
95  BIO *out;
96  out = BIO_new_file("filename.txt", "w");
97  if(!out) /* Error occurred */
98  BIO_printf(out, "Hello World\n");
99  BIO_free(out);
100
101 Alternative technique:
102
103  BIO *out;
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");
108  BIO_free(out);
109
110 =head1 RETURN VALUES
111
112 BIO_s_file() returns the file BIO method.
113
114 BIO_new_file() and BIO_new_fp() return a file BIO or NULL if an error
115 occurred.
116
117 BIO_set_fp() and BIO_get_fp() return 1 for success or 0 for failure
118 (although the current implementation never return 0).
119
120 BIO_seek() returns the same value as the underlying fseek() function:
121 0 for success or -1 for failure.
122
123 BIO_tell() returns the current file position.
124
125 BIO_read_filename(), BIO_write_filename(),  BIO_append_filename() and
126 BIO_rw_filename() return 1 for success or 0 for failure.
127
128 =head1 SEE ALSO
129
130 TBA