RTS API Documentation  1.10.11
switch_platform.h
Go to the documentation of this file.
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 
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 #if __USE_TIME_BITS64
274 #define TIME_T_FMT SWITCH_INT64_T_FMT
275 #else
276 #define TIME_T_FMT "ld"
277 #endif
278 #endif
279 #endif
280 
281 
282 #if UINTPTR_MAX == 0xffffffffffffffff
283 #define FS_64BIT 1
284 #endif
285 
286 #endif
287 
288 #if defined(__sun__) && (defined(__x86_64) || defined(__arch64__))
289 #define SWITCH_TIME_T_FMT SWITCH_SIZE_T_FMT
290 #else
291 #define SWITCH_TIME_T_FMT SWITCH_INT64_T_FMT
292 #endif
293 
295 /* these includes must be outside the extern "C" block on windows or it will break compatibility with c++ modules*/
296 #ifdef WIN32
297 /* Has windows.h already been included? If so, our preferences don't matter,
298  * but we will still need the winsock things no matter what was included.
299  * If not, include a restricted set of windows headers to our tastes.
300  */
301 #ifndef _WINDOWS_
302 #ifndef WIN32_LEAN_AND_MEAN
303 #define WIN32_LEAN_AND_MEAN
304 #endif
305 #ifndef _WIN32_WINNT
306 /* Restrict the server to a subset of Windows NT 4.0 header files by default
307  */
308 #define _WIN32_WINNT 0x0400
309 #endif
310 #ifndef NOUSER
311 #define NOUSER
312 #endif
313 #ifndef NOMCX
314 #define NOMCX
315 #endif
316 #ifndef NOIME
317 #define NOIME
318 #endif
319 #include <windows.h>
320 /*
321  * Add a _very_few_ declarations missing from the restricted set of headers
322  * (If this list becomes extensive, re-enable the required headers above!)
323  * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now
324  */
325 #define SW_HIDE 0
326 #ifndef _WIN32_WCE
327 #include <winsock2.h>
328 #include <mswsock.h>
329 #include <ws2tcpip.h>
330 #else
331 #include <winsock.h>
332 #endif
333 #endif /* !_WINDOWS_ */
334 #include <process.h>
335 #endif
336 #endif
337 #ifndef FALSE
338 #define FALSE 0
339 #endif
340 #ifndef TRUE
341 #define TRUE (!FALSE)
342 #endif
343 #ifndef switch_assert
344 #ifdef PVS_STUDIO // Mute PVS FALSE ALARM
345 #define switch_assert(expr) do {if (!(expr)) {fprintf(stderr, "MEMERR\n"); abort();}} while (0)
346 #else
347 #define switch_assert(expr) assert(expr)
348 #endif
349 #endif
350 #ifndef __ATTR_SAL
351  /* used for msvc code analysis */
352  /* http://msdn2.microsoft.com/en-us/library/ms235402.aspx */
353 #define _In_
354 #define _In_z_
355 #define _In_opt_z_
356 #define _In_opt_
357 #define _Printf_format_string_
358 #define _Ret_opt_z_
359 #define _Ret_z_
360 #define _Out_opt_
361 #define _Out_
362 #define _Check_return_
363 #define _Inout_
364 #define _Inout_opt_
365 #define _In_bytecount_(x)
366 #define _Out_opt_bytecapcount_(x)
367 #define _Out_bytecapcount_(x)
368 #define _Ret_
369 #define _Post_z_
370 #define _Out_cap_(x)
371 #define _Out_z_cap_(x)
372 #define _Out_ptrdiff_cap_(x)
373 #define _Out_opt_ptrdiff_cap_(x)
374 #define _Post_count_(x)
375 #endif
376 #if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
377 #define GCC_DIAG_STR(s) #s
378 #define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
379 # define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
380 # define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
381 # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
382 # define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
383  GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
384 # define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
385 # else
386 # define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
387 # define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(warning GCC_DIAG_JOINSTR(-W,x))
388 # endif
389 #else
390 # define GCC_DIAG_OFF(x)
391 # define GCC_DIAG_ON(x)
392 #endif/* For Emacs:
393  * Local Variables:
394  * mode:c
395  * indent-tabs-mode:t
396  * tab-width:4
397  * c-basic-offset:4
398  * End:
399  * For VIM:
400  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
401  */
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
intptr_t switch_ssize_t
uintptr_t switch_size_t
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42
int32_t switch_int32_t