blob: 4356c2adf44b4eb9d9baf9fb18d9279583fa67b3 (
plain) (
tree)
|
|
/**
* slibc — Yet another C library
* Copyright © 2015, 2016 Mattias Andrée (maandree@member.fsf.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <slibc-alloc.h>
/**
* Variant of `malloc` that extends, or shrinks, an existing allocation,
* if beneficial and possible, or creates a new allocation with the new
* size, copies the data, and frees the old allocation. The returned
* pointer has an alignment usable for any compiler-independent intrinsic
* data type, if a new pointer is returned.
*
* On error, `ptr` is not freed.
*
* @etymology Memory (realloc)ation.
*
* @param ptr Pointer to the beginning of the old memory allocation.
* The process may crash if it does not point to the
* beginning of a memory allocation on the heap.
* However, if it is `NULL`, this function will behave
* like `malloc`.
* @param size The new allocation size. If zero, this function will
* behave like `free`, and will return `NULL`.
* @return Pointer to the beginning of the new allocation.
* If `size` is zero, `NULL` is returned. On error `NULL`
* is returned and `errno` is set to indicate the error.
*
* @throws ENOMEM The process cannot allocate more memory.
*
* @since Always.
*/
void* realloc(void* ptr, size_t size)
{
return fast_realloc(ptr, size);
}
|