doc
|
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 #define INT_TO_POINTER(i) (void *) i 00037 #define POINTER_TO_INT(p) *((int *) (p)) 00038 00039 /** Zero a structure */ 00040 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) 00041 00042 /** Zero a structure given a pointer to the structure */ 00043 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) 00044 00045 /** Free memory and zero the pointer */ 00046 #define SAFE_FREE(x) do { if ((x) != NULL) {free((void*)x); x=NULL;} } while(0) 00047 00048 /** Get the smaller value */ 00049 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 00050 00051 /** Get the bigger value */ 00052 #define MAX(a,b) ((a) < (b) ? (b) : (a)) 00053 00054 /** Get the size of an array */ 00055 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 00056 00057 /** 00058 * }@ 00059 */ 00060 00061 #ifdef _WIN32 00062 /* missing errno codes on mingw */ 00063 #ifndef ENOTBLK 00064 #define ENOTBLK 15 00065 #endif 00066 #ifndef ETXTBSY 00067 #define ETXTBSY 26 00068 #endif 00069 #ifndef ENOBUFS 00070 #define ENOBUFS WSAENOBUFS 00071 #endif 00072 #endif /* _WIN32 */ 00073 00074 #endif /* _C_MACRO_H */ 00075