9be365d4da19b7950f4d8bab5bbd17308588f4af
[samba.git] / source / lib / replace / replace.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    macros to go along with the lib/replace/ portability layer code
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifndef _replace_h
24 #define _replace_h
25
26 #if defined(_MSC_VER) || defined(__MINGW32__)
27 #include "lib/replace/win32/replace.h"
28 #endif
29
30 #ifdef __COMPAR_FN_T
31 #define QSORT_CAST (__compar_fn_t)
32 #endif
33
34 #ifndef QSORT_CAST
35 #define QSORT_CAST (int (*)(const void *, const void *))
36 #endif
37
38 #ifdef HAVE_STDINT_H
39 #include <stdint.h>
40 #endif
41
42 #ifdef HAVE_INTTYPES_H
43 #include <inttypes.h>
44 #endif
45
46 #ifndef HAVE_STRERROR
47 extern char *sys_errlist[];
48 #define strerror(i) sys_errlist[i]
49 #endif
50
51 #ifndef HAVE_ERRNO_DECL
52 extern int errno;
53 #endif
54
55 #ifndef HAVE_STRDUP
56 char *strdup(const char *s);
57 #endif
58
59 #ifndef HAVE_MEMMOVE
60 void *memmove(void *dest,const void *src,int size);
61 #endif
62
63 #ifndef HAVE_MKTIME
64 time_t mktime(struct tm *t);
65 #endif
66
67 #ifndef HAVE_STRLCPY
68 size_t strlcpy(char *d, const char *s, size_t bufsize);
69 #endif
70
71 #ifndef HAVE_STRLCAT
72 size_t strlcat(char *d, const char *s, size_t bufsize);
73 #endif
74
75 #ifndef HAVE_STRNDUP
76 char *strndup(const char *s, size_t n);
77 #endif
78
79 #ifndef HAVE_STRNLEN
80 size_t strnlen(const char *s, size_t n);
81 #endif
82
83 #ifndef HAVE_STRTOUL
84 unsigned long strtoul(const char *nptr, char **endptr, int base);
85 #endif
86
87 #ifndef HAVE_SETENV
88 int setenv(const char *name, const char *value, int overwrite); 
89 #endif
90
91 #ifndef HAVE_RENAME
92 int rename(const char *zfrom, const char *zto);
93 #endif
94
95 #ifndef HAVE_STRCASESTR
96 char *strcasestr(const char *haystack, const char *needle);
97 #endif
98
99 #ifndef HAVE_FTRUNCATE
100 int ftruncate(int f,long l);
101 #endif
102
103 #ifndef HAVE_VASPRINTF_DECL
104 int vasprintf(char **ptr, const char *format, va_list ap);
105 #endif
106
107 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
108 #define bzero(a,b) memset((a),'\0',(b))
109 #endif
110
111 #ifndef PRINTF_ATTRIBUTE
112 #if __GNUC__ >= 3
113 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
114  * the parameter containing the format, and a2 the index of the first
115  * argument. Note that some gcc 2.x versions don't handle this
116  * properly **/
117 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
118 #else
119 #define PRINTF_ATTRIBUTE(a1, a2)
120 #endif
121 #endif
122
123 /* add varargs prototypes with printf checking */
124 #ifndef HAVE_SNPRINTF_DECL
125 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
126 #endif
127 #ifndef HAVE_ASPRINTF_DECL
128 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
129 #endif
130
131
132 /* we used to use these fns, but now we have good replacements
133    for snprintf and vsnprintf */
134 #define slprintf snprintf
135
136
137 #ifndef HAVE_VA_COPY
138 #ifdef HAVE___VA_COPY
139 #define va_copy(dest, src) __va_copy(dest, src)
140 #else
141 #define va_copy(dest, src) (dest) = (src)
142 #endif
143 #endif
144
145 #ifndef HAVE_VOLATILE
146 #define volatile
147 #endif
148
149 #ifndef HAVE_COMPARISON_FN_T
150 typedef int (*comparison_fn_t)(const void *, const void *);
151 #endif
152
153 /* Load header file for dynamic linking stuff */
154 #ifdef HAVE_DLFCN_H
155 #include <dlfcn.h>
156 #endif
157
158 #ifndef RTLD_LAZY
159 #define RTLD_LAZY 0
160 #endif
161
162 #ifndef HAVE_SECURE_MKSTEMP
163 #define mkstemp(path) rep_mkstemp(path)
164 int rep_mkstemp(char *temp);
165 #endif
166
167 #ifdef HAVE_LIMITS_H
168 #include <limits.h>
169 #endif
170
171 /* The extra casts work around common compiler bugs.  */
172 #define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
173 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
174    It is necessary at least when t == time_t.  */
175 #define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \
176                               ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
177 #define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t)))
178
179 #ifndef HOST_NAME_MAX
180 #define HOST_NAME_MAX 64
181 #endif
182
183 #ifndef UINT16_MAX
184 #define UINT16_MAX 65535
185 #endif
186
187 #ifndef UINT32_MAX
188 #define UINT32_MAX (4294967295U)
189 #endif
190
191 #ifndef UINT64_MAX
192 #define UINT64_MAX ((uint64_t)-1)
193 #endif
194
195 #ifndef CHAR_BIT
196 #define CHAR_BIT 8
197 #endif
198
199 #ifndef INT32_MAX
200 #define INT32_MAX _TYPE_MAXIMUM(int32_t)
201 #endif
202
203 #ifdef HAVE_STDBOOL_H
204 #include <stdbool.h>
205 #endif
206
207 #ifndef HAVE_BOOL
208 #define __bool_true_false_are_defined
209 typedef bool int;
210 #define false (0)
211 #define true (1)
212 #endif
213
214 #ifndef HAVE_FUNCTION_MACRO
215 #define __FUNCTION__ ("")
216 #endif
217
218 #ifdef HAVE_SYS_PARAM_H
219 #include <sys/param.h>
220 #endif
221
222 #ifndef MIN
223 #define MIN(a,b) ((a)<(b)?(a):(b))
224 #endif
225
226 #ifndef MAX
227 #define MAX(a,b) ((a)>(b)?(a):(b))
228 #endif
229
230
231
232 #endif