FreeSWITCH API Documentation  1.7.0
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 #if _MSC_VER < 1900
115 #define snprintf _snprintf
116 #endif
117 
118 #else
119 /* packed attribute */
120 #if (defined __SUNPRO_CC) || defined(__SUNPRO_C)
121 #define PACKED
122 #endif
123 #ifndef PACKED
124 #define PACKED __attribute__ ((__packed__))
125 #endif
126 #include <inttypes.h>
127 #include <unistd.h>
128 #include <arpa/inet.h>
129 #include <sys/socket.h>
130 #include <netinet/in.h>
131 #include <netdb.h>
132 #endif // _MSC_VER
133 #ifndef __LITTLE_ENDIAN
134 #define __LITTLE_ENDIAN 1234
135 #endif
136 #ifndef __BIG_ENDIAN
137 #define __BIG_ENDIAN 4321
138 #endif
139 #ifndef __BYTE_ORDER
140 #ifdef SWITCH_BYTE_ORDER
141 #define __BYTE_ORDER SWITCH_BYTE_ORDER
142 #else
143 #define __BYTE_ORDER __LITTLE_ENDIAN
144 #endif
145 #endif
146 #ifdef WIN32
147 #if defined(SWITCH_CORE_DECLARE_STATIC)
148 #define SWITCH_DECLARE(type) type __stdcall
149 #define SWITCH_DECLARE_NONSTD(type) type __cdecl
150 #define SWITCH_DECLARE_DATA
151 #elif defined(FREESWITCHCORE_EXPORTS)
152 #define SWITCH_DECLARE(type) __declspec(dllexport) type __stdcall
153 #define SWITCH_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
154 #define SWITCH_DECLARE_DATA __declspec(dllexport)
155 #else
156 #define SWITCH_DECLARE(type) __declspec(dllimport) type __stdcall
157 #define SWITCH_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
158 #define SWITCH_DECLARE_DATA __declspec(dllimport)
159 #endif
160 #if defined(SWITCH_MOD_DECLARE_STATIC)
161 #define SWITCH_MOD_DECLARE(type) type __stdcall
162 #define SWITCH_MOD_DECLARE_NONSTD(type) type __cdecl
163 #define SWITCH_MOD_DECLARE_DATA
164 #elif defined(MOD_EXPORTS)
165 #define SWITCH_MOD_DECLARE(type) __declspec(dllexport) type __stdcall
166 #define SWITCH_MOD_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
167 #define SWITCH_MOD_DECLARE_DATA __declspec(dllexport)
168 #else
169 #define SWITCH_MOD_DECLARE(type) __declspec(dllimport) type __stdcall
170 #define SWITCH_MOD_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
171 #define SWITCH_MOD_DECLARE_DATA __declspec(dllimport)
172 #endif
173 #define SIGHUP SIGTERM
174 #ifndef S_IRUSR
175 #define S_IRUSR _S_IREAD
176 #endif
177 #ifndef S_IWUSR
178 #define S_IWUSR _S_IWRITE
179 #endif
180 #define SWITCH_THREAD_FUNC __stdcall
181 #define SWITCH_DECLARE_CLASS
182 #else //not win32
183 #define O_BINARY 0
184 #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(SWITCH_API_VISIBILITY)
185 #define SWITCH_DECLARE(type) __attribute__((visibility("default"))) type
186 #define SWITCH_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type
187 #define SWITCH_DECLARE_DATA __attribute__((visibility("default")))
188 #define SWITCH_MOD_DECLARE(type) __attribute__((visibility("default"))) type
189 #define SWITCH_MOD_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type
190 #define SWITCH_MOD_DECLARE_DATA __attribute__((visibility("default")))
191 #define SWITCH_DECLARE_CLASS __attribute__((visibility("default")))
192 #else
193 #define SWITCH_DECLARE(type) type
194 #define SWITCH_DECLARE_NONSTD(type) type
195 #define SWITCH_DECLARE_DATA
196 #define SWITCH_MOD_DECLARE(type) type
197 #define SWITCH_MOD_DECLARE_NONSTD(type) type
198 #define SWITCH_MOD_DECLARE_DATA
199 #define SWITCH_DECLARE_CLASS
200 #endif
201 #define SWITCH_THREAD_FUNC
202 #endif
203 #define SWITCH_DECLARE_CONSTRUCTOR SWITCH_DECLARE_DATA
204 #ifdef DOXYGEN
205 #define DoxyDefine(x) x
206 #else
207 #define DoxyDefine(x)
208 #endif
209 #if __GNUC__ >= 3
210 #define PRINTF_FUNCTION(fmtstr,vars) __attribute__((format(printf,fmtstr,vars)))
211 #else
212 #define PRINTF_FUNCTION(fmtstr,vars)
213 #endif
214 #ifdef SWITCH_INT32
215 typedef SWITCH_INT32 switch_int32_t;
216 #else
217 typedef int32_t switch_int32_t;
218 #endif
219 
220 #ifdef SWITCH_SIZE_T
222 #else
223 typedef uintptr_t switch_size_t;
224 #endif
225 
226 #ifdef SWITCH_SSIZE_T
228 #else
229 typedef intptr_t switch_ssize_t;
230 #endif
231 
232 #ifdef WIN32
233 
234 #ifdef _WIN64
235 #define SWITCH_SSIZE_T_FMT "lld"
236 #define SWITCH_SIZE_T_FMT "lld"
237 #define FS_64BIT 1
238 #else
239 #define SWITCH_SSIZE_T_FMT "d"
240 #define SWITCH_SIZE_T_FMT "d"
241 #endif
242 
243 #define SWITCH_INT64_T_FMT "lld"
244 #define SWITCH_UINT64_T_FMT "llu"
245 
246 #ifndef TIME_T_FMT
247 #define TIME_T_FMT SWITCH_INT64_T_FMT
248 #endif
249 
250 #else
251 #ifndef SWITCH_SSIZE_T_FMT
252 #define SWITCH_SSIZE_T_FMT (sizeof (switch_ssize_t) == sizeof (long) ? "ld" : sizeof (switch_ssize_t) == sizeof (int) ? "d" : "lld")
253 #endif
254 
255 #ifndef SWITCH_SIZE_T_FMT
256 #define SWITCH_SIZE_T_FMT (sizeof (switch_size_t) == sizeof (long) ? "lu" : sizeof (switch_size_t) == sizeof (int) ? "u" : "llu")
257 #endif
258 
259 #ifndef SWITCH_INT64_T_FMT
260 #define SWITCH_INT64_T_FMT (sizeof (long) == 8 ? "ld" : "lld")
261 #endif
262 
263 #ifndef SWITCH_UINT64_T_FMT
264 #define SWITCH_UINT64_T_FMT (sizeof (long) == 8 ? "lu" : "llu")
265 #endif
266 
267 #ifndef TIME_T_FMT
268 #if defined(__FreeBSD__) && SIZEOF_VOIDP == 4
269 #define TIME_T_FMT "d"
270 #else
271 #define TIME_T_FMT "ld"
272 #endif
273 #endif
274 
275 
276 #if UINTPTR_MAX == 0xffffffffffffffff
277 #define FS_64BIT 1
278 #endif
279 
280 #endif
281 
282 #if defined(__sun__) && defined(__x86_64)
283 #define SWITCH_TIME_T_FMT SWITCH_SIZE_T_FMT
284 #else
285 #define SWITCH_TIME_T_FMT SWITCH_INT64_T_FMT
286 #endif
287 
289 /* these includes must be outside the extern "C" block on windows or it will break compatibility with c++ modules*/
290 #ifdef WIN32
291 /* Has windows.h already been included? If so, our preferences don't matter,
292  * but we will still need the winsock things no matter what was included.
293  * If not, include a restricted set of windows headers to our tastes.
294  */
295 #ifndef _WINDOWS_
296 #ifndef WIN32_LEAN_AND_MEAN
297 #define WIN32_LEAN_AND_MEAN
298 #endif
299 #ifndef _WIN32_WINNT
300 /* Restrict the server to a subset of Windows NT 4.0 header files by default
301  */
302 #define _WIN32_WINNT 0x0400
303 #endif
304 #ifndef NOUSER
305 #define NOUSER
306 #endif
307 #ifndef NOMCX
308 #define NOMCX
309 #endif
310 #ifndef NOIME
311 #define NOIME
312 #endif
313 #include <windows.h>
314 /*
315  * Add a _very_few_ declarations missing from the restricted set of headers
316  * (If this list becomes extensive, re-enable the required headers above!)
317  * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now
318  */
319 #define SW_HIDE 0
320 #ifndef _WIN32_WCE
321 #include <winsock2.h>
322 #include <mswsock.h>
323 #include <ws2tcpip.h>
324 #else
325 #include <winsock.h>
326 #endif
327 #endif /* !_WINDOWS_ */
328 #include <process.h>
329 #endif
330 #endif
331 #ifndef FALSE
332 #define FALSE 0
333 #endif
334 #ifndef TRUE
335 #define TRUE (!FALSE)
336 #endif
337 #ifndef switch_assert
338 #define switch_assert(expr) assert(expr)
339 #endif
340 #ifndef __ATTR_SAL
341  /* used for msvc code analysis */
342  /* http://msdn2.microsoft.com/en-us/library/ms235402.aspx */
343 #define _In_
344 #define _In_z_
345 #define _In_opt_z_
346 #define _In_opt_
347 #define _Printf_format_string_
348 #define _Ret_opt_z_
349 #define _Ret_z_
350 #define _Out_opt_
351 #define _Out_
352 #define _Check_return_
353 #define _Inout_
354 #define _Inout_opt_
355 #define _In_bytecount_(x)
356 #define _Out_opt_bytecapcount_(x)
357 #define _Out_bytecapcount_(x)
358 #define _Ret_
359 #define _Post_z_
360 #define _Out_cap_(x)
361 #define _Out_z_cap_(x)
362 #define _Out_ptrdiff_cap_(x)
363 #define _Out_opt_ptrdiff_cap_(x)
364 #define _Post_count_(x)
365 #endif
366 /* For Emacs:
367  * Local Variables:
368  * mode:c
369  * indent-tabs-mode:t
370  * tab-width:4
371  * c-basic-offset:4
372  * End:
373  * For VIM:
374  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
375  */
#define SWITCH_SSIZE_T
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
intptr_t switch_ssize_t
uintptr_t switch_size_t
#define SWITCH_SIZE_T
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42
int32_t switch_int32_t