c_macro.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_macro.h
00025  *
00026  * @brief cynapses libc macro definitions
00027  *
00028  * @defgroup cynMacroInternals cynapses libc macro definitions
00029  * @ingroup cynLibraryAPI
00030  *
00031  * @{
00032  */
00033 #ifndef _C_MACRO_H
00034 #define _C_MACRO_H
00035 
00036 #include <stdlib.h>
00037 #include <string.h>
00038 
00039 #ifdef malloc
00040 #undef malloc
00041 #endif
00042 #define malloc(x) DO_NOT_CALL_MALLOC__USE_C_MALLOC_INSTEAD
00043 
00044 #ifdef calloc
00045 #undef calloc
00046 #endif
00047 #define calloc(x,y) DO_NOT_CALL_CALLOC__USE_C_CALLOC_INSTEAD
00048 
00049 #ifdef realloc
00050 #undef realloc
00051 #endif
00052 #define realloc(x,y) DO_NOT_CALL_REALLOC__USE_C_REALLOC_INSTEAD
00053 
00054 #ifdef dirname
00055 #undef dirname
00056 #endif
00057 #define dirname(x) DO_NOT_CALL_MALLOC__USE_C_DIRNAME_INSTEAD
00058 
00059 #ifdef basename
00060 #undef basename
00061 #endif
00062 #define basename(x) DO_NOT_CALL_MALLOC__USE_C_BASENAME_INSTEAD
00063 
00064 #ifdef strdup
00065 #undef strdup
00066 #endif
00067 #define strdup(x) DO_NOT_CALL_STRDUP__USE_C_STRDUP_INSTEAD
00068 
00069 #define INT_TO_POINTER(i) (void *) i
00070 #define POINTER_TO_INT(p) *((int *) (p))
00071 
00072 /** Zero a structure */
00073 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
00074 
00075 /** Zero a structure given a pointer to the structure */
00076 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
00077 
00078 /** Free memory and zero the pointer */
00079 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
00080 
00081 /** Get the smaller value */
00082 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00083 
00084 /** Get the bigger value */
00085 #define MAX(a,b) ((a) < (b) ? (b) : (a))
00086 
00087 /** Get the size of an array */
00088 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
00089 
00090 /**
00091  * }@
00092  */
00093 #endif /* _C_MACRO_H */
00094 

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