Now using 2 spaces instead of tabs. Fix copyright years. Improve documentation
[cgds.git] / src / safe_alloc.h
1 /**
2 * @file safe_alloc.h
3 * @brief Safe memory management.
4 */
5
6 #ifndef CGDS_SAFE_ALLOC_H
7 #define CGDS_SAFE_ALLOC_H
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 /**
13 * @brief Wrapper around stdlib malloc function.
14 * @return A pointer to the newly allocated area; exit program if fail.
15 */
16 void* safe_malloc(
17 size_t size ///< Size of the block to allocate, in bytes.
18 );
19
20 /**
21 * @brief Wrapper around stdlib calloc function.
22 * @return A pointer to the newly allocated area; exit program if fail.
23 */
24 void* safe_calloc(
25 size_t count, ///< Number of elements to allocate.
26 size_t size ///< Size of the element to allocate, in bytes.
27 );
28
29 /**
30 * @brief Wrapper around stdlib realloc function.
31 * @return A pointer to the newly allocated area; exit program if fail.
32 */
33 void* safe_realloc(
34 void* ptr, ///< Pointer on the area to be relocated.
35 size_t size ///< Size of the block to reallocate, in bytes.
36 );
37
38 /**
39 * @brief Wrapper around stdlib free function.
40 */
41 void safe_free(
42 void* ptr ///< Pointer on the area to be destroyed.
43 );
44
45 #endif