159191Skris=pod
259191Skris
359191Skris=head1 NAME
459191Skris
559191SkrisBUF_MEM_new, BUF_MEM_free, BUF_MEM_grow, BUF_strdup - simple
659191Skrischaracter arrays structure
759191Skris
859191Skris=head1 SYNOPSIS
959191Skris
1059191Skris #include <openssl/buffer.h>
1159191Skris
1259191Skris BUF_MEM *BUF_MEM_new(void);
1359191Skris
1459191Skris void	BUF_MEM_free(BUF_MEM *a);
1559191Skris
1659191Skris int	BUF_MEM_grow(BUF_MEM *str, int len);
1759191Skris
1859191Skris char *	BUF_strdup(const char *str);
1959191Skris
2059191Skris=head1 DESCRIPTION
2159191Skris
2259191SkrisThe buffer library handles simple character arrays. Buffers are used for
2359191Skrisvarious purposes in the library, most notably memory BIOs.
2459191Skris
2559191SkrisThe library uses the BUF_MEM structure defined in buffer.h:
2659191Skris
2759191Skris typedef struct buf_mem_st
2859191Skris {
2959191Skris        int length;     /* current number of bytes */
3059191Skris        char *data;
3159191Skris        int max;        /* size of buffer */
3259191Skris } BUF_MEM;
3359191Skris
3459191SkrisB<length> is the current size of the buffer in bytes, B<max> is the amount of
3559191Skrismemory allocated to the buffer. There are three functions which handle these
3659191Skrisand one "miscellaneous" function.
3759191Skris
3859191SkrisBUF_MEM_new() allocates a new buffer of zero size.
3959191Skris
4059191SkrisBUF_MEM_free() frees up an already existing buffer. The data is zeroed
4159191Skrisbefore freeing up in case the buffer contains sensitive data.
4259191Skris
4359191SkrisBUF_MEM_grow() changes the size of an already existing buffer to
4459191SkrisB<len>. Any data already in the buffer is preserved if it increases in
4559191Skrissize.
4659191Skris
4759191SkrisBUF_strdup() copies a null terminated string into a block of allocated
4859191Skrismemory and returns a pointer to the allocated block.
4968651SkrisUnlike the standard C library strdup() this function uses OPENSSL_malloc() and so
5059191Skrisshould be used in preference to the standard library strdup() because it can
5159191Skrisbe used for memory leak checking or replacing the malloc() function.
5259191Skris
5368651SkrisThe memory allocated from BUF_strdup() should be freed up using the OPENSSL_free()
5459191Skrisfunction.
5559191Skris
5659191Skris=head1 RETURN VALUES
5759191Skris
5859191SkrisBUF_MEM_new() returns the buffer or NULL on error.
5959191Skris
6059191SkrisBUF_MEM_free() has no return value.
6159191Skris
6259191SkrisBUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
6359191Skris
6459191Skris=head1 SEE ALSO
6559191Skris
6659191SkrisL<bio(3)|bio(3)>
6759191Skris
6859191Skris=head1 HISTORY
6959191Skris
7059191SkrisBUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
7168651Skrisversions of SSLeay and OpenSSL. BUF_strdup() was added in SSLeay 0.8.
7259191Skris
7359191Skris=cut
74