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