doc
c_alloc.h
Go to the documentation of this file.
1/*
2 * cynapses libc functions
3 *
4 * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file c_alloc.h
23 *
24 * @brief Interface of the cynapses libc alloc function
25 *
26 * @defgroup cynLibraryAPI cynapses libc API (internal)
27 *
28 * @defgroup cynAllocInternals cynapses libc alloc functions
29 * @ingroup cynLibraryAPI
30 *
31 * @{
32 */
33
34#ifndef _C_ALLOC_H
35#define _C_ALLOC_H
36
37#include <stdlib.h>
38
39#include "c_macro.h"
40
41/**
42 * @brief Allocates memory for an array.
43 *
44 * Allocates memory for an array of <count> elements of <size> bytes each and
45 * returns a pointer to the allocated memory. The memory is set to zero.
46 *
47 * @param count Amount of elements to allocate
48 * @param size Size in bytes of each element to allocate.
49 *
50 * @return A unique pointer value that can later be successfully passed to
51 * free(). If size or count is 0, NULL will be returned.
52 */
53void *c_calloc(size_t count, size_t size);
54
55/**
56 * @brief Allocates memory for an array.
57 *
58 * Allocates <size> bytes of memory. The memory is set to zero.
59 *
60 * @param size Size in bytes to allocate.
61 *
62 * @return A unique pointer value that can later be successfully passed to
63 * free(). If size or count is 0, NULL will be returned.
64 */
65void *c_malloc(size_t size);
66
67/**
68 * @brief Changes the size of the memory block pointed to.
69 *
70 * Newly allocated memory will be uninitialized.
71 *
72 * @param ptr Pointer to the memory which should be resized.
73 * @param size Value to resize.
74 *
75 * @return If ptr is NULL, the call is equivalent to c_malloc(size); if size
76 * is equal to zero, the call is equivalent to free(ptr). Unless ptr
77 * is NULL, it must have been returned by an earlier call to
78 * c_malloc(), c_calloc() or c_realloc(). If the area pointed to was
79 * moved, a free(ptr) is done.
80 */
81void *c_realloc(void *ptr, size_t size);
82
83/**
84 * @brief Duplicate a string.
85 *
86 * The function returns a pointer to a newly allocated string which is a
87 * duplicate of the string str.
88 *
89 * @param str String to duplicate.
90 *
91 * @return Returns a pointer to the duplicated string, or NULL if insufficient
92 * memory was available.
93 *
94 */
95char *c_strdup(const char *str);
96
97/**
98 * @brief Duplicate a string.
99 *
100 * The function returns a pointer to a newly allocated string which is a
101 * duplicate of the string str of size bytes.
102 *
103 * @param str String to duplicate.
104 *
105 * @param size Size of the string to duplicate.
106 *
107 * @return Returns a pointer to the duplicated string, or NULL if insufficient
108 * memory was available. A terminating null byte '\0' is added.
109 *
110 */
111char *c_strndup(const char *str, size_t size);
112
113/**
114 * }@
115 */
116#endif /* _C_ALLOC_H */
cynapses libc macro definitions
off_t size
void * c_malloc(size_t size)
Allocates memory for an array.
char * c_strdup(const char *str)
Duplicate a string.
void * c_calloc(size_t count, size_t size)
Allocates memory for an array.
char * c_strndup(const char *str, size_t size)
Duplicate a string.
void * c_realloc(void *ptr, size_t size)
Changes the size of the memory block pointed to.