---
name: "buffer"
section: "3ssl"
platform: "linux"
package: "libssl-doc"
version: "1.0.1t-1+deb8u8"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/buffer/3ssl"
---

# buffer(3ssl)

simple character array structure BUF\_strdup, BUF\_strndup, BUF\_memdup, BUF\_strlcpy, BUF\_strlcat - standard C library equivalents

## NAME

BUF\_MEM\_new, BUF\_MEM\_new\_ex, BUF\_MEM\_free, BUF\_MEM\_grow - simple character array structure

BUF\_strdup, BUF\_strndup, BUF\_memdup, BUF\_strlcpy, BUF\_strlcat - standard C library equivalents

## SYNOPSIS

```
 #include <openssl/buffer.h>
 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);
 char *BUF_strndup(const char *str, size_t siz);
 void *BUF_memdup(const void *data, size_t siz);
 size_t BUF_strlcpy(char *dst, const char *src, size_t size);
 size_t BUF_strlcat(char *dst, const char *src, size_t size);
```

## DESCRIPTION

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

*BUF\_MEM\_new()* allocates a new buffer of zero size.

*BUF\_MEM\_free()* frees up an already existing buffer. The data is zeroed before freeing up in case the buffer contains sensitive data.

*BUF\_MEM\_grow()* changes the size of an already existing buffer to **len**. Any data already in the buffer is preserved if it increases in size.

*BUF\_strdup()*, *BUF\_strndup()*, *BUF\_memdup()*, *BUF\_strlcpy()* and *BUF\_strlcat()* are equivalents of the standard C library functions. The *dup()* functions use *OPENSSL\_malloc()* underneath and so should be used in preference to the standard library for memory leak checking or replacing the *malloc()* function.

Memory allocated from these functions should be freed up using the *OPENSSL\_free()* function.

BUF\_strndup makes the explicit guarantee that it will never read past the first **siz** bytes of **str**.

## RETURN VALUES

*BUF\_MEM\_new()* returns the buffer or NULL on error.

*BUF\_MEM\_free()* has no return value.

*BUF\_MEM\_grow()* returns zero on error or the new size (i.e. **len**).

## SEE ALSO

*bio*(3)

## HISTORY

*BUF\_MEM\_new()*, *BUF\_MEM\_free()* and *BUF\_MEM\_grow()* are available in all versions of SSLeay and OpenSSL. *BUF\_strdup()* was added in SSLeay 0.8.
