Document BUF_strnlen
[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  #define BUF_MEM_FLAG_SECURE
18
19  BUF_MEM *BUF_MEM_new_ex(unsigned long flags);
20
21  void   BUF_MEM_free(BUF_MEM *a);
22
23  int    BUF_MEM_grow(BUF_MEM *str, int len);
24
25  char *BUF_strdup(const char *str);
26
27  char *BUF_strndup(const char *str, size_t siz);
28
29  void *BUF_memdup(const void *data, size_t siz);
30
31  size_t BUF_strlcpy(char *dst, const char *src, size_t size);
32
33  size_t BUF_strlcat(char *dst, const char *src, size_t size);
34
35  size_t BUF_strnlen(const char *str, size_t maxlen);
36
37 =head1 DESCRIPTION
38
39 The buffer library handles simple character arrays. Buffers are used for
40 various purposes in the library, most notably memory BIOs.
41
42 BUF_MEM_new() allocates a new buffer of zero size.
43
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)>.
47
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.
50
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
53 size.
54
55 BUF_strdup(), BUF_strndup(), BUF_memdup(), BUF_strlcpy(),
56 BUF_strlcat() and BUF_strnlen are equivalents of the standard C
57 library functions. The dup() functions use OPENSSL_malloc() underneath
58 and so should be used in preference to the standard library for memory
59 leak checking or replacing the malloc() function.
60
61 Memory allocated from these functions should be freed up using the
62 OPENSSL_free() function.
63
64 BUF_strndup makes the explicit guarantee that it will never read past
65 the first B<siz> bytes of B<str>.
66
67 =head1 RETURN VALUES
68
69 BUF_MEM_new() returns the buffer or NULL on error.
70
71 BUF_MEM_free() has no return value.
72
73 BUF_MEM_grow() returns zero on error or the new size (i.e. B<len>).
74
75 =head1 SEE ALSO
76
77 L<bio(3)>,
78 L<CRYPTO_secure_malloc(3)>.
79
80 =head1 HISTORY
81
82 BUF_MEM_new(), BUF_MEM_free() and BUF_MEM_grow() are available in all
83 versions of SSLeay and OpenSSL. BUF_strdup() was added in SSLeay 0.8.
84
85 BUF_MEM_new_ex() was contributed to OpenSSL by Akamai Technologies
86 in May, 2014.
87
88 =cut