Merge from vendor branch OPENSSH:
[dragonfly.git] / secure / lib / libcrypto / man / BIO_s_mem.3
1 .\" Automatically generated by Pod::Man version 1.15
2 .\" Wed Feb 19 16:42:45 2003
3 .\"
4 .\" Standard preamble:
5 .\" ======================================================================
6 .de Sh \" Subsection heading
7 .br
8 .if t .Sp
9 .ne 5
10 .PP
11 \fB\\$1\fR
12 .PP
13 ..
14 .de Sp \" Vertical space (when we can't use .PP)
15 .if t .sp .5v
16 .if n .sp
17 ..
18 .de Ip \" List item
19 .br
20 .ie \\n(.$>=3 .ne \\$3
21 .el .ne 3
22 .IP "\\$1" \\$2
23 ..
24 .de Vb \" Begin verbatim text
25 .ft CW
26 .nf
27 .ne \\$1
28 ..
29 .de Ve \" End verbatim text
30 .ft R
31
32 .fi
33 ..
34 .\" Set up some character translations and predefined strings.  \*(-- will
35 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
36 .\" double quote, and \*(R" will give a right double quote.  | will give a
37 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used
38 .\" to do unbreakable dashes and therefore won't be available.  \*(C` and
39 .\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
40 .tr \(*W-|\(bv\*(Tr
41 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
42 .ie n \{\
43 .    ds -- \(*W-
44 .    ds PI pi
45 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
46 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
47 .    ds L" ""
48 .    ds R" ""
49 .    ds C` ""
50 .    ds C' ""
51 'br\}
52 .el\{\
53 .    ds -- \|\(em\|
54 .    ds PI \(*p
55 .    ds L" ``
56 .    ds R" ''
57 'br\}
58 .\"
59 .\" If the F register is turned on, we'll generate index entries on stderr
60 .\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
61 .\" index entries marked with X<> in POD.  Of course, you'll have to process
62 .\" the output yourself in some meaningful fashion.
63 .if \nF \{\
64 .    de IX
65 .    tm Index:\\$1\t\\n%\t"\\$2"
66 ..
67 .    nr % 0
68 .    rr F
69 .\}
70 .\"
71 .\" For nroff, turn off justification.  Always turn off hyphenation; it
72 .\" makes way too many mistakes in technical documents.
73 .hy 0
74 .if n .na
75 .\"
76 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
77 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
78 .bd B 3
79 .    \" fudge factors for nroff and troff
80 .if n \{\
81 .    ds #H 0
82 .    ds #V .8m
83 .    ds #F .3m
84 .    ds #[ \f1
85 .    ds #] \fP
86 .\}
87 .if t \{\
88 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
89 .    ds #V .6m
90 .    ds #F 0
91 .    ds #[ \&
92 .    ds #] \&
93 .\}
94 .    \" simple accents for nroff and troff
95 .if n \{\
96 .    ds ' \&
97 .    ds ` \&
98 .    ds ^ \&
99 .    ds , \&
100 .    ds ~ ~
101 .    ds /
102 .\}
103 .if t \{\
104 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
105 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
106 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
107 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
108 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
109 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
110 .\}
111 .    \" troff and (daisy-wheel) nroff accents
112 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
113 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
114 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
115 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
116 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
117 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
118 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
119 .ds ae a\h'-(\w'a'u*4/10)'e
120 .ds Ae A\h'-(\w'A'u*4/10)'E
121 .    \" corrections for vroff
122 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
123 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
124 .    \" for low resolution devices (crt and lpr)
125 .if \n(.H>23 .if \n(.V>19 \
126 \{\
127 .    ds : e
128 .    ds 8 ss
129 .    ds o a
130 .    ds d- d\h'-1'\(ga
131 .    ds D- D\h'-1'\(hy
132 .    ds th \o'bp'
133 .    ds Th \o'LP'
134 .    ds ae ae
135 .    ds Ae AE
136 .\}
137 .rm #[ #] #H #V #F C
138 .\" ======================================================================
139 .\"
140 .IX Title "BIO_s_mem 3"
141 .TH BIO_s_mem 3 "0.9.7a" "2003-02-19" "OpenSSL"
142 .UC
143 .SH "NAME"
144 BIO_s_mem, BIO_set_mem_eof_return, BIO_get_mem_data, BIO_set_mem_buf,
145 BIO_get_mem_ptr, BIO_new_mem_buf \- memory \s-1BIO\s0
146 .SH "SYNOPSIS"
147 .IX Header "SYNOPSIS"
148 .Vb 1
149 \& #include <openssl/bio.h>
150 .Ve
151 .Vb 1
152 \& BIO_METHOD *   BIO_s_mem(void);
153 .Ve
154 .Vb 4
155 \& BIO_set_mem_eof_return(BIO *b,int v)
156 \& long BIO_get_mem_data(BIO *b, char **pp)
157 \& BIO_set_mem_buf(BIO *b,BUF_MEM *bm,int c)
158 \& BIO_get_mem_ptr(BIO *b,BUF_MEM **pp)
159 .Ve
160 .Vb 1
161 \& BIO *BIO_new_mem_buf(void *buf, int len);
162 .Ve
163 .SH "DESCRIPTION"
164 .IX Header "DESCRIPTION"
165 \&\fIBIO_s_mem()\fR return the memory \s-1BIO\s0 method function. 
166 .PP
167 A memory \s-1BIO\s0 is a source/sink \s-1BIO\s0 which uses memory for its I/O. Data
168 written to a memory \s-1BIO\s0 is stored in a \s-1BUF_MEM\s0 structure which is extended
169 as appropriate to accommodate the stored data.
170 .PP
171 Any data written to a memory \s-1BIO\s0 can be recalled by reading from it.
172 Unless the memory \s-1BIO\s0 is read only any data read from it is deleted from
173 the \s-1BIO\s0.
174 .PP
175 Memory BIOs support \fIBIO_gets()\fR and \fIBIO_puts()\fR.
176 .PP
177 If the \s-1BIO_CLOSE\s0 flag is set when a memory \s-1BIO\s0 is freed then the underlying
178 \&\s-1BUF_MEM\s0 structure is also freed.
179 .PP
180 Calling \fIBIO_reset()\fR on a read write memory \s-1BIO\s0 clears any data in it. On a
181 read only \s-1BIO\s0 it restores the \s-1BIO\s0 to its original state and the read only
182 data can be read again.
183 .PP
184 \&\fIBIO_eof()\fR is true if no data is in the \s-1BIO\s0.
185 .PP
186 \&\fIBIO_ctrl_pending()\fR returns the number of bytes currently stored.
187 .PP
188 \&\fIBIO_set_mem_eof_return()\fR sets the behaviour of memory \s-1BIO\s0 \fBb\fR when it is
189 empty. If the \fBv\fR is zero then an empty memory \s-1BIO\s0 will return \s-1EOF\s0 (that is
190 it will return zero and \fIBIO_should_retry\fR\|(b) will be false. If \fBv\fR is non
191 zero then it will return \fBv\fR when it is empty and it will set the read retry
192 flag (that is \fIBIO_read_retry\fR\|(b) is true). To avoid ambiguity with a normal
193 positive return value \fBv\fR should be set to a negative value, typically \-1.
194 .PP
195 \&\fIBIO_get_mem_data()\fR sets \fBpp\fR to a pointer to the start of the memory BIOs data
196 and returns the total amount of data available. It is implemented as a macro.
197 .PP
198 \&\fIBIO_set_mem_buf()\fR sets the internal \s-1BUF_MEM\s0 structure to \fBbm\fR and sets the
199 close flag to \fBc\fR, that is \fBc\fR should be either \s-1BIO_CLOSE\s0 or \s-1BIO_NOCLOSE\s0.
200 It is a macro.
201 .PP
202 \&\fIBIO_get_mem_ptr()\fR places the underlying \s-1BUF_MEM\s0 structure in \fBpp\fR. It is
203 a macro.
204 .PP
205 \&\fIBIO_new_mem_buf()\fR creates a memory \s-1BIO\s0 using \fBlen\fR bytes of data at \fBbuf\fR,
206 if \fBlen\fR is \-1 then the \fBbuf\fR is assumed to be null terminated and its
207 length is determined by \fBstrlen\fR. The \s-1BIO\s0 is set to a read only state and
208 as a result cannot be written to. This is useful when some data needs to be
209 made available from a static area of memory in the form of a \s-1BIO\s0. The
210 supplied data is read directly from the supplied buffer: it is \fBnot\fR copied
211 first, so the supplied area of memory must be unchanged until the \s-1BIO\s0 is freed.
212 .SH "NOTES"
213 .IX Header "NOTES"
214 Writes to memory BIOs will always succeed if memory is available: that is
215 their size can grow indefinitely.
216 .PP
217 Every read from a read write memory \s-1BIO\s0 will remove the data just read with
218 an internal copy operation, if a \s-1BIO\s0 contains a lots of data and it is
219 read in small chunks the operation can be very slow. The use of a read only
220 memory \s-1BIO\s0 avoids this problem. If the \s-1BIO\s0 must be read write then adding
221 a buffering \s-1BIO\s0 to the chain will speed up the process.
222 .SH "BUGS"
223 .IX Header "BUGS"
224 There should be an option to set the maximum size of a memory \s-1BIO\s0.
225 .PP
226 There should be a way to \*(L"rewind\*(R" a read write \s-1BIO\s0 without destroying
227 its contents.
228 .PP
229 The copying operation should not occur after every small read of a large \s-1BIO\s0
230 to improve efficiency.
231 .SH "EXAMPLE"
232 .IX Header "EXAMPLE"
233 Create a memory \s-1BIO\s0 and write some data to it:
234 .PP
235 .Vb 2
236 \& BIO *mem = BIO_new(BIO_s_mem());
237 \& BIO_puts(mem, "Hello World\en");
238 .Ve
239 Create a read only memory \s-1BIO:\s0
240 .PP
241 .Vb 3
242 \& char data[] = "Hello World";
243 \& BIO *mem;
244 \& mem = BIO_new_mem_buf(data, -1);
245 .Ve
246 Extract the \s-1BUF_MEM\s0 structure from a memory \s-1BIO\s0 and then free up the \s-1BIO:\s0
247 .PP
248 .Vb 4
249 \& BUF_MEM *bptr;
250 \& BIO_get_mem_ptr(mem, &bptr);
251 \& BIO_set_close(mem, BIO_NOCLOSE); /* So BIO_free() leaves BUF_MEM alone */
252 \& BIO_free(mem);
253 .Ve
254 .SH "SEE ALSO"
255 .IX Header "SEE ALSO"
256 \&\s-1TBA\s0