BUF_strdup and friends: update docs
[openssl.git] / doc / crypto / buffer.pod
1 =pod
2
3 =head1 NAME
4
5 BUF_MEM_new, BUF_MEM_new_ex, BUF_MEM_free, BUF_MEM_grow - simple
6 character array structure
7
8 BUF_strdup, BUF_strndup, BUF_memdup, BUF_strlcpy, BUF_strlcat -
9 standard C library equivalents
10
11 =head1 SYNOPSIS
12
13  #include <openssl/buffer.h>
14
15  BUF_MEM *BUF_MEM_new(void);
16
17  void   BUF_MEM_free(BUF_MEM *a);
18
19  int    BUF_MEM_grow(BUF_MEM *str, int len);
20
21  char *BUF_strdup(const char *str);
22
23  char *BUF_strndup(const char *str, size_t siz);
24
25  void *BUF_memdup(const void *data, size_t siz);
26
27  size_t BUF_strlcpy(char *dst, const char *src, size_t size);
28
29  size_t BUF_strlcat(char *dst, const char *src, size_t size);
30
31 =head1 DESCRIPTION
32
33 The buffer library handles simple character arrays. Buffers are used for
34 various purposes in the library, most notably memory BIOs.
35
36 BUF_MEM_new() allocates a new buffer of zero size.
37
38 BUF_MEM_free() frees up an already existing buffer. The data is zeroed
39 before freeing up in case the buffer contains sensitive data.
40
41 BUF_MEM_grow() changes the size of an already existing buffer to
42 B<len>. Any data already in the buffer is preserved if it increases in
43 size.
44
45 BUF_strdup(), BUF_strndup(), BUF_memdup(), BUF_strlcpy() and
46 BUF_strlcat() are equivalents of the standard C library functions. The
47 dup() functions use OPENSSL_malloc() underneath and so should be used
48 in preference to the standard library for memory leak checking or
49 replacing the malloc() function.
50
51 Memory allocated from these functions should be freed up using the
52 OPENSSL_free() function.
53
54 BUF_strndup makes the explicit guarantee that it will never read past
55 the first B<siz> bytes of B<str>.
56
57 =head1 RETURN VALUES
58
59 BUF_MEM_new() returns the buffer or NULL on error.
60
61 BUF_MEM_free() has no return value.
62
63 BUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
64
65 =head1 SEE ALSO
66
67 L<bio(3)|bio(3)>
68
69 =head1 HISTORY
70
71 BUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
72 versions of SSLeay and OpenSSL. BUF_strdup() was added in SSLeay 0.8.
73
74 =cut