buffer.pod 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. =pod
  2. =head1 NAME
  3. BUF_MEM_new, BUF_MEM_free, BUF_MEM_grow, BUF_strdup - simple
  4. character arrays structure
  5. =head1 SYNOPSIS
  6. #include <openssl/buffer.h>
  7. BUF_MEM *BUF_MEM_new(void);
  8. void BUF_MEM_free(BUF_MEM *a);
  9. int BUF_MEM_grow(BUF_MEM *str, int len);
  10. char * BUF_strdup(const char *str);
  11. =head1 DESCRIPTION
  12. The buffer library handles simple character arrays. Buffers are used for
  13. various purposes in the library, most notably memory BIOs.
  14. The library uses the BUF_MEM structure defined in buffer.h:
  15. typedef struct buf_mem_st
  16. {
  17. int length; /* current number of bytes */
  18. char *data;
  19. int max; /* size of buffer */
  20. } BUF_MEM;
  21. B<length> is the current size of the buffer in bytes, B<max> is the amount of
  22. memory allocated to the buffer. There are three functions which handle these
  23. and one "miscellaneous" function.
  24. BUF_MEM_new() allocates a new buffer of zero size.
  25. BUF_MEM_free() frees up an already existing buffer. The data is zeroed
  26. before freeing up in case the buffer contains sensitive data.
  27. BUF_MEM_grow() changes the size of an already existing buffer to
  28. B<len>. Any data already in the buffer is preserved if it increases in
  29. size.
  30. BUF_strdup() copies a null terminated string into a block of allocated
  31. memory and returns a pointer to the allocated block.
  32. Unlike the standard C library strdup() this function uses OPENSSL_malloc() and so
  33. should be used in preference to the standard library strdup() because it can
  34. be used for memory leak checking or replacing the malloc() function.
  35. The memory allocated from BUF_strdup() should be freed up using the OPENSSL_free()
  36. function.
  37. =head1 RETURN VALUES
  38. BUF_MEM_new() returns the buffer or NULL on error.
  39. BUF_MEM_free() has no return value.
  40. BUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
  41. =head1 SEE ALSO
  42. L<bio(3)|bio(3)>
  43. =head1 HISTORY
  44. BUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
  45. versions of SSLeay and OpenSSL. BUF_strdup() was added in SSLeay 0.8.
  46. =cut