65cbd1b7778163855d3b8107d48d52c2cf372193
[samba.git] / source / include / includes.h
1 #ifndef _INCLUDES_H
2 #define _INCLUDES_H
3 /* 
4    Unix SMB/CIFS implementation.
5    Machine customisation and include handling
6    Copyright (C) Andrew Tridgell 1994-1998
7    Copyright (C) 2002 by Martin Pool <mbp@samba.org>
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef NO_CONFIG_H /* for some tests */
25 #include "config.h"
26 #include "smb_build.h"
27 #endif
28
29 #include "local.h"
30
31 #if (__GNUC__ >= 3)
32 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
33  * the parameter containing the format, and a2 the index of the first
34  * argument. Note that some gcc 2.x versions don't handle this
35  * properly **/
36 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
37 #else
38 #define PRINTF_ATTRIBUTE(a1, a2)
39 #endif
40
41 #ifdef __GNUC__
42 /** gcc attribute used on function parameters so that it does not emit
43  * warnings about them being unused. **/
44 #  define UNUSED(param) param __attribute__ ((unused))
45 #else
46 #  define UNUSED(param) param
47 /** Feel free to add definitions for other compilers here. */
48 #endif
49
50 #include <sys/types.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <stddef.h>
54 #include <sys/time.h>
55
56 #ifdef HAVE_STDINT_H
57 #include <stdint.h>
58 #endif
59
60 #ifdef HAVE_STRING_H
61 #include <string.h>
62 #endif
63
64 #include <signal.h>
65 #include <errno.h>
66
67 #ifdef HAVE_STDARG_H
68 #include <stdarg.h>
69 #else
70 #include <varargs.h>
71 #endif
72
73 /* we support ADS if we want it and have krb5 and ldap libs */
74 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
75 #define HAVE_ADS
76 #endif
77
78 /*
79  * Define VOLATILE if needed.
80  */
81
82 #if defined(HAVE_VOLATILE)
83 #define VOLATILE volatile
84 #else
85 #define VOLATILE
86 #endif
87
88 #define False (0)
89 #define True (1)
90 #define Auto (2)
91
92 typedef int BOOL;
93
94 /*
95   we use struct ipv4_addr to avoid having to include all the
96   system networking headers everywhere
97 */
98 struct ipv4_addr {
99         uint32_t addr;
100 };
101
102 #ifndef HAVE_STRERROR
103 extern char *sys_errlist[];
104 #define strerror(i) sys_errlist[i]
105 #endif
106
107 #ifndef HAVE_ERRNO_DECL
108 extern int errno;
109 #endif
110
111 /* Lists, trees, caching, database... */
112 #include "xfile.h"
113 #include "lib/talloc/talloc.h"
114 #include "nt_status.h"
115 #include "structs.h"
116 #include "trans2.h"
117 #include "nterr.h"
118 #include "charset.h"
119 #include "debug.h"
120 #include "doserr.h"
121 #include "enums.h"
122 #include "smb_macros.h"
123 #include "smb.h"
124 #include "byteorder.h"
125 #include "module.h"
126 #include "librpc/ndr/libndr.h"
127 #include "librpc/gen_ndr/ndr_misc.h"
128 #include "librpc/gen_ndr/ndr_dcerpc.h"
129 #include "librpc/ndr/ndr_orpc.h"
130 #include "librpc/gen_ndr/ndr_orpc.h"
131 #include "librpc/rpc/dcerpc.h"
132 #include "smb_interfaces.h"
133 #include "ntvfs/ntvfs.h"
134 #include "cli_context.h"
135 #include "lib/com/com.h"
136 #include "credentials.h"
137
138 #define malloc_p(type) (type *)malloc(sizeof(type))
139 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
140 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
141
142 #ifndef HAVE_COMPARISON_FN_T
143 typedef int (*comparison_fn_t)(const void *, const void *);
144 #endif
145
146 /***** automatically generated prototypes *****/
147 #define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2)
148 #include "proto.h"
149 #undef _PRINTF_ATTRIBUTE
150 #define _PRINTF_ATTRIBUTE(a1, a2)
151
152 /* String routines */
153
154 #include "safe_string.h"
155
156 #ifdef __COMPAR_FN_T
157 #define QSORT_CAST (__compar_fn_t)
158 #endif
159
160 #ifndef QSORT_CAST
161 #define QSORT_CAST (int (*)(const void *, const void *))
162 #endif
163
164 #ifndef HAVE_PIPE
165 #define SYNC_DNS 1
166 #endif
167
168 #ifndef HAVE_STRDUP
169 char *strdup(const char *s);
170 #endif
171
172 #ifndef HAVE_MEMMOVE
173 void *memmove(void *dest,const void *src,int size);
174 #endif
175
176 #ifndef HAVE_MKTIME
177 time_t mktime(struct tm *t);
178 #endif
179
180 #ifndef HAVE_STRLCPY
181 size_t strlcpy(char *d, const char *s, size_t bufsize);
182 #endif
183
184 #ifndef HAVE_STRLCAT
185 size_t strlcat(char *d, const char *s, size_t bufsize);
186 #endif
187
188 #ifndef HAVE_STRNDUP
189 char *strndup(const char *s, size_t n);
190 #endif
191
192 #ifndef HAVE_STRNLEN
193 size_t strnlen(const char *s, size_t n);
194 #endif
195
196 #ifndef HAVE_STRTOUL
197 unsigned long strtoul(const char *nptr, char **endptr, int base);
198 #endif
199
200 #ifndef HAVE_SETENV
201 int setenv(const char *name, const char *value, int overwrite); 
202 #endif
203
204 #ifndef HAVE_VASPRINTF_DECL
205 int vasprintf(char **ptr, const char *format, va_list ap);
206 #endif
207
208 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
209 #define bzero(a,b) memset((a),'\0',(b))
210 #endif
211
212 extern int DEBUGLEVEL;
213
214 /* add varargs prototypes with printf checking */
215 #ifndef HAVE_SNPRINTF_DECL
216 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
217 #endif
218 #ifndef HAVE_ASPRINTF_DECL
219 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
220 #endif
221
222
223 /* we used to use these fns, but now we have good replacements
224    for snprintf and vsnprintf */
225 #define slprintf snprintf
226
227
228 #ifdef HAVE_VA_COPY
229 #define VA_COPY(dest, src) va_copy(dest, src)
230 #elif defined(HAVE___VA_COPY)
231 #define VA_COPY(dest, src) __va_copy(dest, src)
232 #else
233 #define VA_COPY(dest, src) (dest) = (src)
234 #endif
235
236 #if defined(VALGRIND)
237 #define strlen(x) valgrind_strlen(x)
238 #endif
239
240 #if 0
241 /* darn, we can't do this now that we don't link the ldb tools to all the smb libs */
242 #define TALLOC_ABORT(reason) smb_panic(reason)
243 #endif
244
245 /*
246   this is a warning hack. The idea is to use this everywhere that we
247   get the "discarding const" warning from gcc. That doesn't actually
248   fix the problem of course, but it means that when we do get to
249   cleaning them up we can do it by searching the code for
250   discard_const.
251
252   It also means that other error types aren't as swamped by the noise
253   of hundreds of const warnings, so we are more likely to notice when
254   we get new errors.
255
256   Please only add more uses of this macro when you find it
257   _really_ hard to fix const warnings. Our aim is to eventually use
258   this function in only a very few places.
259
260   Also, please call this via the discard_const_p() macro interface, as that
261   makes the return type safe.
262 */
263 #ifdef HAVE_INTPTR_T
264 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
265 #else
266 #define discard_const(ptr) ((void *)(ptr))
267 #endif
268 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
269
270 #ifndef UINT16_MAX
271 #define UINT16_MAX 65535
272 #endif
273
274 /*
275   type safe varient of smb_xmalloc()
276 */
277 #define smb_xmalloc_p(type) (type *)smb_xmalloc(sizeof(type))
278
279 #endif /* _INCLUDES_H */
280