1.Dd $Mdocdate: March 12 2016 $ 2.Dt BUF_MEM_NEW 3 3.Os 4.Sh NAME 5.Nm BUF_MEM_new , 6.Nm BUF_MEM_free , 7.Nm BUF_MEM_grow , 8.Nm BUF_strdup 9.Nd simple character arrays structure 10.Sh SYNOPSIS 11.In openssl/buffer.h 12.Ft BUF_MEM * 13.Fo BUF_MEM_new 14.Fa void 15.Fc 16.Ft void 17.Fo BUF_MEM_free 18.Fa "BUF_MEM *a" 19.Fc 20.Ft int 21.Fo BUF_MEM_grow 22.Fa "BUF_MEM *str" 23.Fa "size_t len" 24.Fc 25.Ft char * 26.Fo BUF_strdup 27.Fa "const char *str" 28.Fc 29.Sh DESCRIPTION 30The buffer library handles simple character arrays. 31Buffers are used for various purposes in the library, most notably 32memory BIOs. 33.Pp 34The library uses the 35.Vt BUF_MEM 36structure defined in buffer.h: 37.Bd -literal 38typedef struct buf_mem_st 39{ 40 size_t length; /* current number of bytes */ 41 char *data; 42 size_t max; /* size of buffer */ 43} BUF_MEM; 44.Ed 45.Pp 46.Fa length 47is the current size of the buffer in bytes, 48.Fa max 49is the amount of memory allocated to the buffer. 50There are three functions which handle these and one 51.Dq miscellaneous 52function. 53.Pp 54.Fn BUF_MEM_new 55allocates a new buffer of zero size. 56.Pp 57.Fn BUF_MEM_free 58frees up an already existing buffer. 59The data is zeroed before freeing up in case the buffer contains 60sensitive data. 61.Pp 62.Fn BUF_MEM_grow 63changes the size of an already existing buffer to 64.Fa len . 65Any data already in the buffer is preserved if it increases in size. 66.Pp 67.Fn BUF_strdup 68copies a NUL terminated string into a block of allocated memory and 69returns a pointer to the allocated block. 70Unlike the system 71.Xr strdup 3 72function, 73.Fn BUF_strdup 74will accept a 75.Dv NULL 76argument and will return 77.Dv NULL 78in that case. 79Its use in new programs is discouraged. 80.Pp 81The memory allocated from 82.Fn BUF_strdup 83should be freed up using the 84.Xr free 3 85function. 86.Sh RETURN VALUES 87.Fn BUF_MEM_new 88returns the buffer or 89.Dv NULL 90on error. 91.Pp 92.Fn BUF_MEM_grow 93returns zero on error or the new size (i.e. 94.Fa len Ns ). 95.Sh SEE ALSO 96.Xr bio 3 97.Sh HISTORY 98.Fn BUF_MEM_new , 99.Fn BUF_MEM_free 100and 101.Fn BUF_MEM_grow 102are available in all versions of SSLeay and OpenSSL. 103.Fn BUF_strdup 104was added in SSLeay 0.8. 105