5 BUF_MEM_new, BUF_MEM_free, BUF_MEM_grow, BUF_strdup - simple
6 character arrays structure
10 #include <openssl/buffer.h>
12 BUF_MEM *BUF_MEM_new(void);
14 #define BUF_MEM_FLAG_SECURE
16 BUF_MEM * BUF_MEM_new_ex(unsigned long flags);
18 void BUF_MEM_free(BUF_MEM *a);
20 int BUF_MEM_grow(BUF_MEM *str, int len);
22 char * BUF_strdup(const char *str);
26 The buffer library handles simple character arrays. Buffers are used for
27 various purposes in the library, most notably memory BIOs.
29 The library uses the BUF_MEM structure defined in buffer.h:
31 typedef struct buf_mem_st
33 int length; /* current number of bytes */
35 int max; /* size of buffer */
38 B<length> is the current size of the buffer in bytes, B<max> is the amount of
39 memory allocated to the buffer. There are three functions which handle these
40 and one "miscellaneous" function.
42 BUF_MEM_new() allocates a new buffer of zero size.
44 BUF_MEM_new_ex() allocates a buffer with the specified flags.
45 The flag B<BUF_MEM_FLAG_SECURE> specifies that the B<data> pointer
46 should be allocated on the secure heap; see L<CRYPTO_secure_malloc(3)>.
48 BUF_MEM_free() frees up an already existing buffer. The data is zeroed
49 before freeing up in case the buffer contains sensitive data.
51 BUF_MEM_grow() changes the size of an already existing buffer to
52 B<len>. Any data already in the buffer is preserved if it increases in
55 BUF_strdup() copies a null terminated string into a block of allocated
56 memory and returns a pointer to the allocated block.
57 Unlike the standard C library strdup() this function uses OPENSSL_malloc() and so
58 should be used in preference to the standard library strdup() because it can
59 be used for memory leak checking or replacing the malloc() function.
61 The memory allocated from BUF_strdup() should be freed up using the OPENSSL_free()
66 BUF_MEM_new() returns the buffer or NULL on error.
68 BUF_MEM_free() has no return value.
70 BUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
75 L<CRYPTO_secure_malloc(3)>.
79 BUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
80 versions of SSLeay and OpenSSL. BUF_strdup() was added in SSLeay 0.8.
82 BUF_MEM_new_ex() was contributed to OpenSSL by Akamai Technologies