doc
c_macro.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_macro.h
25  *
26  * @brief cynapses libc macro definitions
27  *
28  * @defgroup cynMacroInternals cynapses libc macro definitions
29  * @ingroup cynLibraryAPI
30  *
31  * @{
32  */
33 #ifndef _C_MACRO_H
34 #define _C_MACRO_H
35 
36 #define INT_TO_POINTER(i) (void *) i
37 #define POINTER_TO_INT(p) *((int *) (p))
38 
39 /** Zero a structure */
40 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
41 
42 /** Zero a structure given a pointer to the structure */
43 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
44 
45 /** Free memory and zero the pointer */
46 #define SAFE_FREE(x) do { if ((x) != NULL) {free((void*)x); x=NULL;} } while(0)
47 
48 /** Get the smaller value */
49 #define MIN(a,b) ((a) < (b) ? (a) : (b))
50 
51 /** Get the bigger value */
52 #define MAX(a,b) ((a) < (b) ? (b) : (a))
53 
54 /** Get the size of an array */
55 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
56 
57 /**
58  * }@
59  */
60 
61 #ifdef _WIN32
62 /* missing errno codes on mingw */
63 #ifndef ENOTBLK
64 #define ENOTBLK 15
65 #endif
66 #ifndef ETXTBSY
67 #define ETXTBSY 26
68 #endif
69 #ifndef ENOBUFS
70 #define ENOBUFS WSAENOBUFS
71 #endif
72 #endif /* _WIN32 */
73 
74 #endif /* _C_MACRO_H */
75