buffer 3 2001-04-12 0.9.9-dev OpenSSL

NAME

BUF_MEM_new, BUF_MEM_free, BUF_MEM_grow, BUF_strdup - simple character arrays structure

LIBRARY

libcrypto, -lcrypto

SYNOPSIS


 #include 


 BUF_MEM *BUF_MEM_new(void);


 void   BUF_MEM_free(BUF_MEM *a);


 int    BUF_MEM_grow(BUF_MEM *str, int len);


 char * BUF_strdup(const char *str);

DESCRIPTION

The buffer library handles simple character arrays. Buffers are used for various purposes in the library, most notably memory BIOs.

The library uses the BUF_MEM structure defined in buffer.h:





 typedef struct buf_mem_st
 {
        int length;     /* current number of bytes */
        char *data;
        int max;        /* size of buffer */
 } BUF_MEM;

lleennggtthh is the current size of the buffer in bytes, mmaaxx is the amount of memory allocated to the buffer. There are three functions which handle these and one "miscellaneous" function.

_B_U_F___M_E_M___n_e_w_(_) allocates a new buffer of zero size.

_B_U_F___M_E_M___f_r_e_e_(_) frees up an already existing buffer. The data is zeroed before freeing up in case the buffer contains sensitive data.

_B_U_F___M_E_M___g_r_o_w_(_) changes the size of an already existing buffer to lleenn. Any data already in the buffer is preserved if it increases in size.

_B_U_F___s_t_r_d_u_p_(_) copies a null terminated string into a block of allocated memory and returns a pointer to the allocated block. Unlike the standard C library _s_t_r_d_u_p_(_) this function uses _O_P_E_N_S_S_L___m_a_l_l_o_c_(_) and so should be used in preference to the standard library _s_t_r_d_u_p_(_) because it can be used for memory leak checking or replacing the _m_a_l_l_o_c_(_) function.

The memory allocated from _B_U_F___s_t_r_d_u_p_(_) should be freed up using the _O_P_E_N_S_S_L___f_r_e_e_(_) function.

RETURN VALUES

_B_U_F___M_E_M___n_e_w_(_) returns the buffer or NULL on error.

_B_U_F___M_E_M___f_r_e_e_(_) has no return value.

_B_U_F___M_E_M___g_r_o_w_(_) returns zero on error or the new size (i.e. lleenn).

SEE ALSO

_o_p_e_n_s_s_l___b_i_o(3)

HISTORY

_B_U_F___M_E_M___n_e_w_(_), _B_U_F___M_E_M___f_r_e_e_(_) and _B_U_F___M_E_M___g_r_o_w_(_) are available in all versions of SSLeay and OpenSSL. _B_U_F___s_t_r_d_u_p_(_) was added in SSLeay 0.8.