Check-in Lasker-2.2.3 tar ball from samba.org
[capablanca.git] / lasker-2.2.3 / src / common.h
1 /*
2    Copyright (c) 1993 Richard V. Nash.
3    Copyright (c) 2000 Dan Papasian
4    Copyright (C) Andrew Tridgell 2002
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (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
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21
22 #ifndef _COMMON_H
23 #define _COMMON_H
24
25 #ifndef MAX 
26 #define MAX(x,y)  (((x)>(y))? (x):(y))
27 #endif
28 #ifndef MIN
29 #define MIN(x,y)  (((x)>(y))? (y):(x))
30 #endif
31
32 #ifndef NULL
33 #define NULL ((void *)0)
34 #endif
35
36 #define SWAP(a,b,type) {\
37   type tmp; \
38   tmp = (a);\
39   (a) = (b);\
40   (b) = tmp;\
41 }
42
43 #define ZERO_STRUCT(s) memset(&(s), 0, sizeof(s))
44 #define ZERO_STRUCTP(s) memset(s, 0, sizeof(*(s)))
45
46
47 #ifdef __GNUC__
48 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
49  * the parameter containing the format, and a2 the index of the first
50  * argument.  **/
51 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
52 #else
53 #define PRINTF_ATTRIBUTE(a1, a2)
54 #endif
55
56
57 /* declare some printf style functions so the compiler checks the args */
58 FILE *fopen_p(const char *fmt, const char *mode, ...) PRINTF_ATTRIBUTE(1,3);
59 int asprintf(char **strp, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
60 void d_printf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
61 int pprintf(int p, char *format,...) PRINTF_ATTRIBUTE(2,3);
62 int pprintf_highlight(int p, char *format,...) PRINTF_ATTRIBUTE(2,3);
63 int psprintf_highlight(int p, char *s, char *format,...) PRINTF_ATTRIBUTE(3,4);
64 int pprintf_prompt(int p, char *format,...) PRINTF_ATTRIBUTE(2,3);
65 int pprintf_noformat(int p, char *format,...) PRINTF_ATTRIBUTE(2,3);
66 int pcommand(int p, char *comstr,...) PRINTF_ATTRIBUTE(2,3);
67
68
69
70 /* prototypes for replacement functions */
71 #ifndef HAVE_DPRINTF
72 int dprintf(int fd, const char *format, ...);
73 #endif
74 #ifndef HAVE_STRNLEN
75 size_t strnlen(const char *s, size_t n);
76 #endif
77
78 #ifndef HAVE_STRLCPY
79 size_t strlcpy(char *d, const char *s, size_t bufsize);
80 #endif
81 #ifndef HAVE_STRLCAT
82 size_t strlcat(char *d, const char *s, size_t bufsize);
83 #endif
84
85 #if HAVE_COMPAR_FN_T
86 #define COMPAR_FN_T __compar_fn_t
87 #else
88 typedef int (*COMPAR_FN_T)(const void *, const void *);
89 #endif
90
91 /* tell tdb that it can use mmap */
92 #define HAVE_MMAP 1
93
94 #endif /* _COMMON_H */