c_alloc.h

Go to the documentation of this file.
00001 /*
00002  * cynapses libc functions
00003  *
00004  * Copyright (c) 2008 by Andreas Schneider <mail@cynapses.org>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  * vim: ts=2 sw=2 et cindent
00021  */
00022 
00023 /**
00024  * @file c_alloc.h
00025  *
00026  * @brief Interface of the cynapses libc alloc function
00027  *
00028  * @defgroup cynLibraryAPI cynapses libc API (internal)
00029  *
00030  * @defgroup cynAllocInternals cynapses libc alloc functions
00031  * @ingroup cynLibraryAPI
00032  *
00033  * @{
00034  */
00035 
00036 #ifndef _C_ALLOC_H
00037 #define _C_ALLOC_H
00038 
00039 #include <stdlib.h>
00040 
00041 #include "c_macro.h"
00042 
00043 /**
00044  * @brief Allocates memory for an array.
00045  *
00046  * Allocates memory for an array of <count> elements of <size> bytes each and
00047  * returns a pointer to the allocated memory. The memory is set to zero.
00048  *
00049  * @param count   Amount of elements to allocate
00050  * @param size    Size in bytes of each element to allocate.
00051  *
00052  * @return A unique pointer value that can later be successfully passed to
00053  *         free(). If size or count is 0, NULL will be returned.
00054  */
00055 void *c_calloc(size_t count, size_t size);
00056 
00057 /**
00058  * @brief Allocates memory for an array.
00059  *
00060  * Allocates <size> bytes of memory. The memory is set to zero.
00061  *
00062  * @param size    Size in bytes to allocate.
00063  *
00064  * @return A unique pointer value that can later be successfully passed to
00065  *         free(). If size or count is 0, NULL will be returned.
00066  */
00067 void *c_malloc(size_t size);
00068 
00069 /**
00070  * @brief Changes the size of the memory block pointed to.
00071  *
00072  * Newly allocated memory will be uninitialized.
00073  *
00074  * @param ptr   Pointer to the memory which should be resized.
00075  * @param size  Value to resize.
00076  *
00077  * @return If ptr is NULL, the call is equivalent to c_malloc(size); if size
00078  *         is equal to zero, the call is equivalent to free(ptr). Unless ptr
00079  *         is NULL, it must have been returned by an earlier call to
00080  *         c_malloc(), c_calloc() or c_realloc(). If the area pointed to was
00081  *         moved, a free(ptr) is done.
00082  */
00083 void *c_realloc(void *ptr, size_t size);
00084 
00085 /**
00086  * @brief Duplicate a string.
00087  *
00088  * The function returns a pointer to a newly allocated string which is a
00089  * duplicate of the string str.
00090  *
00091  * @param str   String to duplicate.
00092  *
00093  * @return Returns a pointer to the duplicated string, or NULL if insufficient
00094  * memory was available.
00095  *
00096  */
00097 char *c_strdup(const char *str);
00098 
00099 /**
00100  * @brief Duplicate a string.
00101  *
00102  * The function returns a pointer to a newly allocated string which is a
00103  * duplicate of the string str of size bytes.
00104  *
00105  * @param str   String to duplicate.
00106  *
00107  * @param size  Size of the string to duplicate.
00108  *
00109  * @return Returns a pointer to the duplicated string, or NULL if insufficient
00110  * memory was available. A terminating null byte '\0' is added.
00111  *
00112  */
00113 char *c_strndup(const char *str, size_t size);
00114 
00115 /**
00116  * }@
00117  */
00118 #endif /* _C_ALLOC_H */

Generated on Mon May 4 17:43:35 2009 for doc by  doxygen 1.5.6