mem.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org>
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00016 
00017 /*!
00018  * @defgroup mem Memory area manipulation
00019  *
00020  * @{
00021  */
00022 
00023 #ifndef _LUCID_MEM_H
00024 #define _LUCID_MEM_H
00025 
00026 /*!
00027  * @brief allocate memory
00028  *
00029  * @param[in]  n allocate n bytes
00030  *
00031  * @return A pointer to newly allocated memory, NULL otherwise.
00032  */
00033 void *mem_alloc(int n);
00034 
00035 /*!
00036  * @brief copy memory block until character is found
00037  *
00038  * @param[out] s1 pointer to destination block
00039  * @param[in]  s2 pointer to source block
00040  * @param[in]  n  copy first n bytes of s2
00041  *
00042  * @return A pointer to s1.
00043  */
00044 void *mem_ccpy(void *s1, const void *s2, int c, int n);
00045 
00046 /*!
00047  * @brief find character in memory block
00048  *
00049  * @param[in] s pointer to memory block
00050  * @param[in] c character to look for
00051  * @param[in] n scan first n bytes
00052  *
00053  * @return A pointer to the first matching character found, NULL otherwise.
00054  */
00055 void *mem_chr(const void *s, int c, int n);
00056 
00057 /*!
00058  * @brief compare two memory regions
00059  *
00060  * @param[in] s1 pointer to first memory region
00061  * @param[in] s2 pointer to second memory region
00062  * @param[in] n  compare n bytes
00063  *
00064  * @return An integer less than, equal to, or greater than zero according to
00065  *         whether s1 is lexicographically less than, equal to, or greater
00066  *         than s2.
00067  */
00068 int mem_cmp(const void *s1, const void *s2, int n);
00069 
00070 /*!
00071  * @brief copy memory block
00072  *
00073  * @param[out] s1 pointer to destination block
00074  * @param[in]  s2 pointer to source block
00075  * @param[in]  n  copy first n bytes of s2
00076  *
00077  * @return A pointer to s1.
00078  */
00079 void *mem_cpy(void *s1, const void *s2, int n);
00080 
00081 /*!
00082  * @brief duplicate a memory block
00083  *
00084  * @param[in] s pointer to source memory area
00085  * @param[in] n duplicate first n bytes
00086  *
00087  * @return A pointer to the duplicated memory block, or NULL if insufficient
00088  *         memory was available.
00089  */
00090 void *mem_dup(const void *s, int n);
00091 
00092 /*!
00093  * @brief free memory
00094  *
00095  * @param[in]  s memory area to free
00096  */
00097 void mem_free(void *s);
00098 
00099 /*!
00100  * @brief free all memory
00101  */
00102 void mem_freeall(void);
00103 
00104 
00105 /*!
00106  * @brief find character in memory block
00107  *
00108  * @param[out] s pointer to memory block
00109  * @param[in]  c character to look for
00110  * @param[in]  n scan first n bytes
00111  *
00112  * @return An integer offset to the character in the memory block starting at s.
00113  *
00114  * @note This function will scan any number of bytes until a NULL character is
00115  *       found if n is less than or equal to zero.
00116  */
00117 int mem_idx(const void *s, int c, int n);
00118 
00119 /*!
00120  * @brief reallocate memory
00121  *
00122  * @param[in]  s memory area to reallocate
00123  * @param[in]  n allocate n bytes
00124  *
00125  * @return A pointer to newly allocated memory, NULL otherwise.
00126  */
00127 void *mem_realloc(void *s, int n);
00128 
00129 /*!
00130  * @brief fill memory block with character
00131  *
00132  * @param[out] s pointer to memory block
00133  * @param[in]  c character value to be set
00134  * @param[in]  n fill first n bytes
00135  *
00136  * @return A pointer to s1.
00137  */
00138 void *mem_set(void *s, int c, int n);
00139 
00140 #endif
00141 
00142 /*! @} mem */

Generated on Tue Jun 19 20:38:26 2007 for lucid by  doxygen 1.5.2