reallocf(3bsd) 3bsd reallocf(3bsd)

# [NAME](#NAME)

`reallocf` — general purpose memory allocation functions

# [LIBRARY](#LIBRARY)

library “libbsd”

# [SYNOPSIS](#SYNOPSIS)

`#include <stdlib.h>` (See [libbsd(7)](/man/os/libbsd/libbsd.7) for include usage.)  
`void *`  
`reallocf`(`void *ptr`, `size_t size`);

# [DESCRIPTION](#DESCRIPTION)

The [`reallocf`](#reallocf)() function changes the size of the previously allocated memory referenced by `ptr` to `size` bytes. The contents of the memory are unchanged up to the lesser of the new and old sizes. If the new size is larger, the contents of the newly allocated portion of the memory are undefined. Upon success, the memory referenced by `ptr` is freed and a pointer to the newly allocated memory is returned. Note that `reallocf`() may move the memory allocation, resulting in a different return value than `ptr`. If `ptr` is `NULL`, the `reallocf`() function behaves identically to [`malloc`](#malloc)() for the specified size. Upon failure, when the requested memory cannot be allocated, the passed pointer is freed to ease the problems with traditional coding styles for `reallocf`() causing memory leaks in libraries.

# [RETURN VALUES](#RETURN_VALUES)

The `reallocf`() function returns a pointer, possibly identical to `ptr`, to the allocated memory if successful; otherwise a `NULL` pointer is returned, and `errno` is set to `ENOMEM` if the error was the result of an allocation failure. The buffer is deallocated in this case.

# [SEE ALSO](#SEE_ALSO)

[brk(2)](/man/os/libbsd/brk.2), [mmap(2)](/man/os/libbsd/mmap.2), [alloca(3)](/man/os/libbsd/alloca.3), [calloc(3)](/man/os/libbsd/calloc.3), [free(3)](/man/os/libbsd/free.3), [malloc(3)](/man/os/libbsd/malloc.3), [posix\_memalign(3)](/man/os/libbsd/posix_memalign.3), [realloc(3)](/man/os/libbsd/realloc.3),

# [HISTORY](#HISTORY)

The `reallocf`() function first appeared in FreeBSD 3.0.

September 26, 2009 Linux 4.19.0-gvisor

---

Document: reallocf(3bsd) from libbsd 0.12.2-r8 (Chainguard OS)
Source: https://gitlab.freedesktop.org/libbsd/libbsd
