Move the SSL_CTX_xxx defines at the top of ssl.h to the location of other
[openssl.git] / doc / buffer.txt
1 BUFFER Library.
2
3 [Note: I wrote this when I saw a Malloc version of strdup() in there which
4  I'd written myself anyway. I was so annoyed at not noticing this I decided to
5  document it :-) Steve.]
6
7 The buffer library handles simple character arrays. Buffers are used for various
8 purposes in the library, most notably memory BIOs.
9
10 The library uses the BUF_MEM structure defined in buffer.h:
11
12 typedef struct buf_mem_st
13         {
14         int length;     /* current number of bytes */
15         char *data;
16         int max;        /* size of buffer */
17         } BUF_MEM;
18
19 'length' is the current size of the buffer in bytes, 'max' is the amount of
20 memory allocated to the buffer. There are three functions which handle these
21 and one "miscelanous" function.
22
23 BUF_MEM *BUF_MEM_new()
24
25 This allocates a new buffer of zero size. Returns the buffer or NULL on error.
26
27 void BUF_MEM_free(BUF_MEM *a)
28
29 This frees up an already existing buffer. The data is zeroed before freeing
30 up in case the buffer contains sensitive data.
31
32 int BUF_MEM_grow(BUF_MEM *str, int len)
33
34 This changes the size of an already existing buffer. It returns zero on error
35 or the new size (i.e. 'len'). Any data already in the buffer is preserved if
36 it increases in size.
37
38 char * BUF_strdup(char *str)
39
40 This is the previously mentioned strdup function: like the standard library
41 strdup() it copies a null terminated string into a block of allocated memory
42 and returns a pointer to the allocated block.
43
44 Unlike the standard C library strdup() this function uses Malloc() and so
45 should be used in preference to the standard library strdup() because it can
46 be used for memory leak checking or replacing the malloc() function.
47
48 The memory allocated from BUF_strdup() should be freed up using the Free()
49 function.