1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  *
28  * switch_platform.h -- Platform Specific Header
29  *
30  */
31 /*! \file switch_platform.h
32     \brief Platform Specific Header
33 */
34 #ifndef SWITCH_PLATFORM_H
35 #define SWITCH_PLATFORM_H
36 
37 SWITCH_BEGIN_EXTERN_C
38 #define SWITCH_USE_CLOCK_FUNCS
39 
40 #if defined(WIN32) && defined(_MSC_VER)
41 #define atoll _atoi64
42 #endif
43 #ifdef __ICC
44 #pragma warning (disable:810 869 981 279 1469 188)
45 #endif
46 #include <stdio.h>
47 #define SWITCH_VA_NONE "%s", ""
48 #ifdef _MSC_VER
49 #define __SWITCH_FUNC__ __FUNCTION__
50 #else
51 #define __SWITCH_FUNC__ (const char *)__func__
52 #endif
53 #ifdef _MSC_VER
54 /* disable the following warnings
55  * C4100: The formal parameter is not referenced in the body of the function. The unreferenced parameter is ignored.
56  * C4200: Non standard extension C zero sized array
57  * C4204: nonstandard extension used : non-constant aggregate initializer
58  * C4706: assignment within conditional expression
59  * C4819: The file contains a character that cannot be represented in the current code page
60  * C4132: 'object' : const object should be initialized (fires innapropriately for prototyped forward declaration of cost var)
61  * C4510: default constructor could not be generated
62  * C4512: assignment operator could not be generated
63  * C4610: struct  can never be instantiated - user defined constructor required
64  */
65 #pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610 4996)
66 #define SWITCH_HAVE_ODBC 1
67 #ifdef _MSC_VER
68 #  pragma comment(lib, "odbc32.lib")
69 #endif
70 #pragma include_alias(<libteletone.h>,				<../../libs/libteletone/src/libteletone.h>)
71 #pragma include_alias(<libteletone_generate.h>,		<../../libs/libteletone/src/libteletone_generate.h>)
72 #pragma include_alias(<libteletone_detect.h>,		<../../libs/libteletone/src/libteletone_detect.h>)
73 #if (_MSC_VER >= 1400)			// VC8+
74 #define switch_assert(expr) assert(expr);__analysis_assume( expr )
75 #endif
76 #if (_MSC_VER >= 1400)			// VC8+
77 #ifndef _CRT_SECURE_NO_DEPRECATE
78 #define _CRT_SECURE_NO_DEPRECATE
79 #endif
80 #ifndef _CRT_NONSTDC_NO_DEPRECATE
81 #define _CRT_NONSTDC_NO_DEPRECATE
82 #endif
83 #endif // VC8+
84 #if  _MSC_VER < 1300
85 #ifndef __FUNCTION__
86 #define __FUNCTION__ ""
87 #endif
88 #endif
89 #ifndef __cplusplus
90 #undef inline
91 #define inline __inline
92 #endif
93 #if defined(_MSC_VER) && _MSC_VER >= 1900 && !defined(_STDINT)
94 #include <stdint.h>
95 #endif
96 #if !defined(_STDINT) && !defined(uint32_t)
97 typedef unsigned __int8 uint8_t;
98 typedef unsigned __int16 uint16_t;
99 typedef unsigned __int32 uint32_t;
100 typedef unsigned __int64 uint64_t;
101 typedef __int8 int8_t;
102 typedef __int16 int16_t;
103 typedef __int32 int32_t;
104 typedef __int64 int64_t;
105 typedef unsigned long in_addr_t;
106 #endif
107 typedef int pid_t;
108 typedef int uid_t;
109 typedef int gid_t;
110 #define PACKED
111 #include <io.h>
112 #define strcasecmp(s1, s2) stricmp(s1, s2)
113 #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
114 #else
115 /* packed attribute */
116 #if (defined __SUNPRO_CC) || defined(__SUNPRO_C)
117 #define PACKED
118 #endif
119 #ifndef PACKED
120 #define PACKED __attribute__ ((__packed__))
121 #endif
122 #include <inttypes.h>
123 #include <unistd.h>
124 #include <arpa/inet.h>
125 #include <sys/socket.h>
126 #include <netinet/in.h>
127 #include <netdb.h>
128 #endif // _MSC_VER
129 #ifndef __LITTLE_ENDIAN
130 #define __LITTLE_ENDIAN 1234
131 #endif
132 #ifndef __BIG_ENDIAN
133 #define __BIG_ENDIAN 4321
134 #endif
135 #ifndef __BYTE_ORDER
136 #ifdef SWITCH_BYTE_ORDER
137 #define __BYTE_ORDER SWITCH_BYTE_ORDER
138 /* solaris */
139 #elif defined(__SVR4) && defined(__sun) && defined(_BIG_ENDIAN)
140 #define __BYTE_ORDER __BIG_ENDIAN
141 /* BSD */
142 #elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
143 #define __BYTE_ORDER __BIG_ENDIAN
144 #else
145 #define __BYTE_ORDER __LITTLE_ENDIAN
146 #endif
147 #endif
148 #ifdef WIN32
149 #if defined(SWITCH_CORE_DECLARE_STATIC)
150 #define SWITCH_DECLARE(type)			type __stdcall
151 #define SWITCH_DECLARE_NONSTD(type)		type __cdecl
152 #define SWITCH_DECLARE_DATA
153 #elif defined(FREESWITCHCORE_EXPORTS)
154 #define SWITCH_DECLARE(type)			__declspec(dllexport) type __stdcall
155 #define SWITCH_DECLARE_NONSTD(type)		__declspec(dllexport) type __cdecl
156 #define SWITCH_DECLARE_DATA				__declspec(dllexport)
157 #else
158 #define SWITCH_DECLARE(type)			__declspec(dllimport) type __stdcall
159 #define SWITCH_DECLARE_NONSTD(type)		__declspec(dllimport) type __cdecl
160 #define SWITCH_DECLARE_DATA				__declspec(dllimport)
161 #endif
162 #if defined(SWITCH_MOD_DECLARE_STATIC)
163 #define SWITCH_MOD_DECLARE(type)		type __stdcall
164 #define SWITCH_MOD_DECLARE_NONSTD(type)	type __cdecl
165 #define SWITCH_MOD_DECLARE_DATA
166 #elif defined(MOD_EXPORTS)
167 #define SWITCH_MOD_DECLARE(type)		__declspec(dllexport) type __stdcall
168 #define SWITCH_MOD_DECLARE_NONSTD(type)	__declspec(dllexport) type __cdecl
169 #define SWITCH_MOD_DECLARE_DATA			__declspec(dllexport)
170 #else
171 #define SWITCH_MOD_DECLARE(type)		__declspec(dllimport) type __stdcall
172 #define SWITCH_MOD_DECLARE_NONSTD(type)	__declspec(dllimport) type __cdecl
173 #define SWITCH_MOD_DECLARE_DATA			__declspec(dllimport)
174 #endif
175 #define SIGHUP SIGTERM
176 #ifndef S_IRUSR
177 #define S_IRUSR _S_IREAD
178 #endif
179 #ifndef S_IWUSR
180 #define S_IWUSR _S_IWRITE
181 #endif
182 #define SWITCH_THREAD_FUNC  __stdcall
183 #define SWITCH_DECLARE_CLASS
184 #else //not win32
185 #define O_BINARY 0
186 #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(SWITCH_API_VISIBILITY)
187 #define SWITCH_DECLARE(type)		__attribute__((visibility("default"))) type
188 #define SWITCH_DECLARE_NONSTD(type)	__attribute__((visibility("default"))) type
189 #define SWITCH_DECLARE_DATA		__attribute__((visibility("default")))
190 #define SWITCH_MOD_DECLARE(type)	__attribute__((visibility("default"))) type
191 #define SWITCH_MOD_DECLARE_NONSTD(type)	__attribute__((visibility("default"))) type
192 #define SWITCH_MOD_DECLARE_DATA		__attribute__((visibility("default")))
193 #define SWITCH_DECLARE_CLASS		__attribute__((visibility("default")))
194 #else
195 #define SWITCH_DECLARE(type)		type
196 #define SWITCH_DECLARE_NONSTD(type)	type
197 #define SWITCH_DECLARE_DATA
198 #define SWITCH_MOD_DECLARE(type)	type
199 #define SWITCH_MOD_DECLARE_NONSTD(type)	type
200 #define SWITCH_MOD_DECLARE_DATA
201 #define SWITCH_DECLARE_CLASS
202 #endif
203 #define SWITCH_THREAD_FUNC
204 #endif
205 #define SWITCH_DECLARE_CONSTRUCTOR SWITCH_DECLARE_DATA
206 #ifdef DOXYGEN
207 #define DoxyDefine(x) x
208 #else
209 #define DoxyDefine(x)
210 #endif
211 #if __GNUC__ >= 3
212 #define PRINTF_FUNCTION(fmtstr,vars) __attribute__((format(printf,fmtstr,vars)))
213 #else
214 #define PRINTF_FUNCTION(fmtstr,vars)
215 #endif
216 #ifdef SWITCH_INT32
217 typedef SWITCH_INT32 switch_int32_t;
218 #else
219 typedef int32_t switch_int32_t;
220 #endif
221 
222 #ifdef SWITCH_SIZE_T
223 typedef SWITCH_SIZE_T switch_size_t;
224 #else
225 typedef uintptr_t switch_size_t;
226 #endif
227 
228 #ifdef SWITCH_SSIZE_T
229 typedef SWITCH_SSIZE_T switch_ssize_t;
230 #else
231 typedef intptr_t switch_ssize_t;
232 #endif
233 
234 #ifdef WIN32
235 
236 #ifdef _WIN64
237 #define SWITCH_SSIZE_T_FMT          "lld"
238 #define SWITCH_SIZE_T_FMT           "lld"
239 #define FS_64BIT 1
240 #else
241 #define SWITCH_SSIZE_T_FMT          "d"
242 #define SWITCH_SIZE_T_FMT           "d"
243 #endif
244 
245 #define SWITCH_INT64_T_FMT          "lld"
246 #define SWITCH_UINT64_T_FMT         "llu"
247 
248 #ifndef TIME_T_FMT
249 #define TIME_T_FMT SWITCH_INT64_T_FMT
250 #endif
251 
252 #else
253 #ifndef SWITCH_SSIZE_T_FMT
254 #define SWITCH_SSIZE_T_FMT          (sizeof (switch_ssize_t) == sizeof (long) ? "ld" : sizeof (switch_ssize_t) == sizeof (int) ? "d" : "lld")
255 #endif
256 
257 #ifndef SWITCH_SIZE_T_FMT
258 #define SWITCH_SIZE_T_FMT           (sizeof (switch_size_t) == sizeof (long) ? "lu" : sizeof (switch_size_t) == sizeof (int) ? "u" : "llu")
259 #endif
260 
261 #ifndef SWITCH_INT64_T_FMT
262 #define SWITCH_INT64_T_FMT          (sizeof (long) == 8 ? "ld" : "lld")
263 #endif
264 
265 #ifndef SWITCH_UINT64_T_FMT
266 #define SWITCH_UINT64_T_FMT         (sizeof (long) == 8 ? "lu" : "llu")
267 #endif
268 
269 #ifndef TIME_T_FMT
270 #if defined(__FreeBSD__) && SIZEOF_VOIDP == 4
271 #define TIME_T_FMT "d"
272 #else
273 #define TIME_T_FMT "ld"
274 #endif
275 #endif
276 
277 
278 #if UINTPTR_MAX == 0xffffffffffffffff
279 #define FS_64BIT 1
280 #endif
281 
282 #endif
283 
284 #if defined(__sun__) && (defined(__x86_64) || defined(__arch64__))
285 #define SWITCH_TIME_T_FMT SWITCH_SIZE_T_FMT
286 #else
287 #define SWITCH_TIME_T_FMT SWITCH_INT64_T_FMT
288 #endif
289 
290 SWITCH_END_EXTERN_C
291 /* these includes must be outside the extern "C" block on windows or it will break compatibility with c++ modules*/
292 #ifdef WIN32
293 /* Has windows.h already been included?  If so, our preferences don't matter,
294  * but we will still need the winsock things no matter what was included.
295  * If not, include a restricted set of windows headers to our tastes.
296  */
297 #ifndef _WINDOWS_
298 #ifndef WIN32_LEAN_AND_MEAN
299 #define WIN32_LEAN_AND_MEAN
300 #endif
301 #ifndef _WIN32_WINNT
302 /* Restrict the server to a subset of Windows NT 4.0 header files by default
303  */
304 #define _WIN32_WINNT 0x0400
305 #endif
306 #ifndef NOUSER
307 #define NOUSER
308 #endif
309 #ifndef NOMCX
310 #define NOMCX
311 #endif
312 #ifndef NOIME
313 #define NOIME
314 #endif
315 #include <windows.h>
316 /*
317  * Add a _very_few_ declarations missing from the restricted set of headers
318  * (If this list becomes extensive, re-enable the required headers above!)
319  * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now
320  */
321 #define SW_HIDE             0
322 #ifndef _WIN32_WCE
323 #include <winsock2.h>
324 #include <mswsock.h>
325 #include <ws2tcpip.h>
326 #else
327 #include <winsock.h>
328 #endif
329 #endif /* !_WINDOWS_ */
330 #include <process.h>
331 #endif
332 #endif
333 #ifndef FALSE
334 #define FALSE 0
335 #endif
336 #ifndef TRUE
337 #define TRUE (!FALSE)
338 #endif
339 #ifndef switch_assert
340 #ifdef PVS_STUDIO // Mute PVS FALSE ALARM
341 #define switch_assert(expr) do {if (!(expr)) {fprintf(stderr, "MEMERR\n"); abort();}} while (0)
342 #else
343 #define switch_assert(expr) assert(expr)
344 #endif
345 #endif
346 #ifndef __ATTR_SAL
347 	/* used for msvc code analysis */
348 	/* http://msdn2.microsoft.com/en-us/library/ms235402.aspx */
349 #define _In_
350 #define _In_z_
351 #define _In_opt_z_
352 #define _In_opt_
353 #define _Printf_format_string_
354 #define _Ret_opt_z_
355 #define _Ret_z_
356 #define _Out_opt_
357 #define _Out_
358 #define _Check_return_
359 #define _Inout_
360 #define _Inout_opt_
361 #define _In_bytecount_(x)
362 #define _Out_opt_bytecapcount_(x)
363 #define _Out_bytecapcount_(x)
364 #define _Ret_
365 #define _Post_z_
366 #define _Out_cap_(x)
367 #define _Out_z_cap_(x)
368 #define _Out_ptrdiff_cap_(x)
369 #define _Out_opt_ptrdiff_cap_(x)
370 #define _Post_count_(x)
371 #endif
372 #if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
373 #define GCC_DIAG_STR(s) #s
374 #define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
375 # define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
376 # define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
377 # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
378 #  define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
379 	GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
380 #  define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
381 # else
382 #  define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
383 #  define GCC_DIAG_ON(x)  GCC_DIAG_PRAGMA(warning GCC_DIAG_JOINSTR(-W,x))
384 # endif
385 #else
386 # define GCC_DIAG_OFF(x)
387 # define GCC_DIAG_ON(x)
388 #endif/* For Emacs:
389  * Local Variables:
390  * mode:c
391  * indent-tabs-mode:t
392  * tab-width:4
393  * c-basic-offset:4
394  * End:
395  * For VIM:
396  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
397  */
398