mbgtools-lx  4.2.8
mbg_tgt.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbg_tgt.h 1.45 2019/02/11 09:53:02 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Check the build environment and setup control definitions
10  * for the Meinberg library modules.
11  *
12  * -----------------------------------------------------------------------
13  * $Log: mbg_tgt.h $
14  * Revision 1.45 2019/02/11 09:53:02 martin
15  * Support the mingw build environment.
16  * Changed inclusion of winsock2.h/windows.h on Windows.
17  * Removed obsolete RCS log entries.
18  * Revision 1.44 2018/12/11 15:34:15 martin
19  * Older Visual Studio versions don't support _strtoi64().
20  * Revision 1.43 2018/11/22 11:28:01Z martin
21  * New preprocessor symbol MBG_TGT_USE_IOCTL.
22  * Provide 'uintptr_t' for old Linux kernels.
23  * Removed obsolete Windows driver stuff.
24  * Revision 1.42 2018/09/20 09:40:21 martin
25  * Define MBG_TGT_MISSTNG_STRTOLL and
26  * MBG_TGT_MISSING_LLDDIV_T, if appropriate.
27  * Revision 1.41 2018/08/23 10:49:56Z martin
28  * Enhanced handling of Windows DDK builds.
29  * Revision 1.40 2018/07/02 16:57:49Z martin
30  * Removed obsolete define MBG_USE_MM_IO_FOR_PCI.
31  * Revision 1.39 2018/06/25 10:52:00 martin
32  * Support MBG_TGT_NO_TGT.
33  * Default settings for KERNEL_HAS_BOOL and KERNEL_HAS_TRUE_FALSE
34  * for Linux can be overridden by project settings.
35  * Renamed MBG_PRE64_PREFIX to MBG_PRI_64_PREFIX.
36  * MBG_PRI_64_PREFIX_L or MBG_PRI_64_PREFIX_LL can be used
37  * to override the defaults with specific project settings.
38  * MBG_TGT_HAS_DEV_FN is supported on Windows, but
39  * MBG_TGT_HAS_DEV_FN_BASE is not supported.
40  * Enhanced debug support for Windows kernel drivers.
41  * Include limits.h under Windows.
42  * Defined MBG_TGT_MISSING_STRUCT_TIMESPEC for Borland C.
43  * Defined __func__ for BC 5 and for DOS, and provide a
44  * common default declaration..
45  * Updated some comments.
46  * Revision 1.38 2017/08/08 13:07:31 martin
47  * Proper fix for PRId64 and others.
48  * Define _CRT_SECURE_NO_WARNINGS only if not already defined.
49  * Revision 1.37 2017/07/10 07:08:45 thomas-b
50  * Define PRId64 if it is not defined in inttypes.h
51  * Revision 1.36 2017/07/04 12:35:11 martin
52  * Fixed build for Windows kernel space.
53  * Don't define ssize_t if HAVE_SSIZE_T is already defined.
54  * Added definition for _NO_MBG_API.
55  * Fixed missing 'bool' type for old Linux kernels.
56  * Fixed missing 'struct timespec' for DOS.
57  * Evaluate preprocessor symbol KERNEL_HAS_BOOL to avoid
58  * compiler errors due to duplicate definitions in specific
59  * Linux kernels patched by the distro maintainers.
60  * Provide ssize_t for C++Builder 5.
61  * Improved Visual Studio version checking.
62  * New define MBG_TGT_HAS_NODE_NAME.
63  * Revision 1.35 2016/08/05 12:21:34 martin
64  * Conditionally define a macro _DEPRECATED_BY which can be used to
65  * tag functions as deprecated, so compilers can emit appropriate warnings.
66  * New symbol MBG_TGT_HAS_ABS64.
67  * Moved some compatibility definitions from gpsserio.h here.
68  * Define ssize_t for Windows, if required.
69  * Conditionally provided struct timespec for Windows.
70  * Added compatible 64 bit type print format specifiers.
71  * Include inttypes.h for all targets providing also stdint.h.
72  * Added some MSVC version code information.
73  * Fixes for FreeBSD.
74  * Fixed some spelling.
75  * Tmp workaround for 2.6.32-5-sparc64.
76  * Proper fix required.
77  * Revision 1.34 2015/03/03 13:32:49 martin
78  * Provide __func__ for MS Visual Studio.
79  * Revision 1.33 2015/03/02 11:27:59Z martin
80  * Windows only:
81  * Define _CRT_SECURE_NO_WARNINGS to quiet compiler warnings.
82  * Define WIN32_LEAN_AND_MEAN only if it hasn't been defined before.
83  * Revision 1.32 2014/06/24 09:21:44 martin
84  * Update for newer C++Builder versions.
85  * Revision 1.31 2014/05/27 10:23:33 martin
86  * Finer control of which types are required for or already
87  * available on particular target systems.
88  * First definitions to support SunOS/Solaris.
89  * Revision 1.30 2014/04/01 12:55:58 martin
90  * Define MBG_TGT_WIN32 also for MS resource compiler.
91  * New target MBG_TGT_POSIX.
92  * Always include winsock2.h and windows.h for MBG_TGT_WIN32.
93  * Always include unistd.h for MBG_TGT_POSIX.
94  * Define empty __attribute__ macro for non-gcc environments.
95  * Revision 1.29 2013/02/01 14:50:46 martin
96  * Fixed a typo which caused an error under Borland CBuilder 5.
97  * Revision 1.28 2012/12/12 10:03:16Z martin
98  * Fix for Borland C 3.1.
99  * Revision 1.27 2012/11/29 12:03:14Z martin
100  * Moved definition of _no_macro_fnc() to words.h.
101  * Revision 1.26 2012/11/02 09:01:47Z martin
102  * Merged some stuff depending on the build environment here
103  * and cleaned up.
104  * Revision 1.25 2012/04/04 07:17:18 martin
105  * Treat QNX Neutrino as Unix target.
106  * Revision 1.24 2011/08/23 10:21:23 martin
107  * New symbol _NO_MBG_API_ATTR which can be used with functions
108  * which are going to be exported by a DLL, but actually aren't, yet.
109  * Revision 1.23 2011/08/19 10:47:00 martin
110  * Don't include stddef.h.
111  * Distinguish between different gcc target platforms.
112  * Initial support for IA64 platform.
113  * Support wchar_t for BSD.
114  * Defined _NO_USE_PACK_INTF for Sparc and IA64.
115  * Fixed typo in comment.
116  * Revision 1.22 2009/10/01 08:20:50 martin
117  * Fixed inline code support with different BC versions.
118  * Revision 1.21 2009/09/01 10:34:23Z martin
119  * Don't define __mbg_inline for CVI and undefined targets.
120  * Revision 1.20 2009/08/18 15:14:26 martin
121  * Defined default MBG_INVALID_PORT_HANDLE for non-Windows targets.
122  * Revision 1.19 2009/06/09 10:03:58 daniel
123  * Preliminary support for ARM architecture.
124  * Revision 1.18 2009/04/01 14:10:55 martin
125  * Cleanup for CVI.
126  * Revision 1.17 2009/03/19 15:21:07Z martin
127  * Conditionally define DWORD_PTR type for old MS C compilers.
128  * Revision 1.16 2008/12/08 16:42:30 martin
129  * Defined _GNU_SOURCE for Linux.
130  * Revision 1.15 2008/11/19 15:31:49 martin
131  * Added symbol MBG_ARCH_I386.
132  * Revision 1.14 2008/09/03 15:06:04 martin
133  * Support DOS protected mode target.
134  * Support SUN SPARC architecture.
135  * Specified handle types for common host environments.
136  * Added macro MBG_USE_MM_IO_FOR_PCI.
137  * Added macro _nop_macro_fnc().
138  * Revision 1.13 2008/01/30 15:52:22 martin
139  * Modified checking for availability of wchar_t.
140  * Revision 1.13 2008/01/29 15:18:07Z martin
141  * Recognize DOS target under Watcom compilers.
142  * Flag Watcom C always supports wchar_t.
143  * Revision 1.12 2008/01/17 09:38:50Z daniel
144  * Added macros to determine whether C language extensions
145  * (e.g. C94, C99) are supported by the target environment.
146  * Added macro to check whether wchar_t and friends are
147  * supported, and some compatibility stuff.
148  * Revision 1.11 2007/10/31 16:58:03 martin
149  * Fixed __mbg_inline for Borland C (DOS).
150  * Revision 1.10 2007/09/25 08:10:27Z martin
151  * Support CVI target environment.
152  * Added MBG_PORT_HANDLE type for serial ports.
153  * Added macros for unified inline code syntax.
154  * Revision 1.9 2006/12/08 12:45:54Z martin
155  * Under Windows include ntddk.h rather than windows.h
156  * if building kernel driver .
157  * Revision 1.8 2006/10/25 12:20:45Z martin
158  * Initial support for FreeBSD, NetBSD, and OpenBSD.
159  * Added definitions for generic handle types.
160  * Revision 1.7 2006/08/23 13:43:55 martin
161  * Added definition for MBG_TGT_UNIX.
162  * Minor syntax fixes.
163  * Revision 1.6 2006/01/25 14:37:06 martin
164  * Added definitions for 64 bit Windows environments.
165  * Revision 1.5 2003/12/17 16:11:41Z martin
166  * Split API modifiers into _MBG_API and _MBG_API_ATTR.
167  * Revision 1.4 2003/06/19 08:20:22Z martin
168  * Added WINAPI attribute for DLL exported functions.
169  * Revision 1.3 2003/04/09 13:37:20Z martin
170  * Added definition for _MBG_API.
171  * Revision 1.2 2003/02/24 16:08:45Z martin
172  * Don't setup for Win32 PNP if explicitly configured non-PNP.
173  * Revision 1.1 2002/02/19 13:46:20Z MARTIN
174  * Initial revision
175  *
176  **************************************************************************/
177 
178 #ifndef _MBG_TGT_H
179 #define _MBG_TGT_H
180 
181 
182 /* Other headers to be included */
183 
184 #ifdef MBG_TGT_NO_TGT
185  #include <mbg_no_tgt.h>
186 #else
187 
188 #ifdef _MBG_TGT
189  #define _ext
190 #else
191  #define _ext extern
192 #endif
193 
194 
195 /* Start of header body */
196 
197 #ifdef __cplusplus
198 extern "C" {
199 #endif
200 
201 // The prefix required in a printf() format string to print an
202 // int64_t type (i.e. "%li", "%lli", "I64i", etc.) may vary depending
203 // on the compiler type and version, and the associated run time library.
204 // For user space applications this is usually defined in the header
205 // files provided by the build environment, but for kernel code there
206 // are often no such defines, but there are some commonly used defaults.
207 // This is a hack that can be used to override these defaults in the
208 // project settings for kernel code, e.g. in the Makefile.
209 #if defined( MBG_PRI_64_PREFIX_L )
210  #define MBG_PRI_64_PREFIX "l"
211 #elif defined( MBG_PRI_64_PREFIX_LL )
212  #define MBG_PRI_64_PREFIX "ll"
213 #endif
214 
215 
216 #if defined( _CVI_ )
217 
218  #define MBG_TGT_CVI
219 
220  #if defined( _NI_mswin_ )
221  #define MBG_TGT_WIN32
222  #else
223  #error Unsupported CVI target platform.
224  #endif
225 
226 #elif defined( _WIN32_WINNT )
227 
228  // MS platform SDK
229  // WinNT 4.0 and above
230  #define MBG_TGT_WIN32
231 
232  #if ( _WIN32_WINNT >= 0x0500 )
233  // Win2k and above
234  #if !defined( MBG_TGT_WIN32_NON_PNP )
235  // only if not explicitly disabled
236  #define MBG_TGT_WIN32_PNP
237  #endif
238  #endif
239 
240 #elif defined( WINVER )
241 
242  // MS platform SDK
243  // Win95, WinNT 4.0 and above
244  #define MBG_TGT_WIN32
245 
246  #if ( WINVER >= 0x0500 )
247  // Win98, Win2k and above
248  // #define ...
249  #endif
250 
251 #elif defined( __WIN32__ )
252 
253  // Borland C++ Builder
254  #define MBG_TGT_WIN32
255 
256 #elif defined( _WIN32 )
257 
258  // MS Visual C++
259  #define MBG_TGT_WIN32
260 
261 #elif defined( RC_INVOKED )
262 
263  // MS resource compiler
264  #define MBG_TGT_WIN32
265 
266 #elif defined( __WINDOWS_386__ )
267 
268  // Watcom C/C++ for target Win32
269  #define MBG_TGT_WIN32
270 
271 #elif defined( __NETWARE_386__ )
272 
273  // Watcom C/C++ for target NetWare
274  #define MBG_TGT_NETWARE
275 
276 #elif defined( __OS2__ )
277 
278  // Watcom C/C++ for target OS/2
279  #define MBG_TGT_OS2
280  #define MBG_TGT_USE_IOCTL 1
281 
282 #elif defined( __linux )
283 
284  // GCC for target Linux
285  #define MBG_TGT_LINUX
286  #define _GNU_SOURCE 1
287 
288  #if defined( __KERNEL__ )
289  #define MBG_TGT_KERNEL
290  #endif
291 
292 #elif defined( __FreeBSD__ )
293 
294  // GCC for target FreeBSD
295  #define MBG_TGT_FREEBSD
296 
297 #elif defined( __NetBSD__ )
298 
299  // GCC for target NetBSD
300  #define MBG_TGT_NETBSD
301 
302 #elif defined( __OpenBSD__ )
303 
304  // GCC for target OpenBSD
305  #define MBG_TGT_OPENBSD
306 
307 #elif defined( __sun ) // Oracle Solaris or other SunOS derived operating system
308 
309  // __SUNPRO_C Oracle Solaris Studio C compiler, __SUNPRO_C value is the version number
310  // __SUNPRO_CC Oracle Solaris Studio C++ compiler, __SUNPRO_CC value is the version number
311  // __sparc generate code for SPARC (R) architecture (32-bit or 64-bit)
312  // __sparcv9 generate code for 64-bit SPARC architecture
313  // __i386 generate code for 32-bit x86 architecture
314  // __amd64 generate code for 64-bit x64 architecture
315 
316  #define MBG_TGT_SUNOS
317 
318 #elif defined( __QNX__ )
319 
320  // any compiler for target QNX
321  #define MBG_TGT_QNX
322 
323  #if defined( __QNXNTO__ )
324  // target QNX Neutrino
325  #define MBG_TGT_QNX_NTO
326  #endif
327 
328 #elif defined( __MSDOS__ ) || defined( __DOS__ )
329 
330  // any compiler for target DOS
331  #define MBG_TGT_DOS
332 
333  #if defined( __WATCOMC__ ) && defined( __386__ )
334 
335  #define MBG_TGT_DOS_PM // protected mode DOS
336 
337  #endif
338 
339 #endif
340 
341 
342 
343 #if defined( MBG_TGT_FREEBSD ) \
344  || defined( MBG_TGT_NETBSD ) \
345  || defined( MBG_TGT_OPENBSD )
346  #define MBG_TGT_BSD
347 
348  #if defined( _KERNEL )
349  #define MBG_TGT_KERNEL
350  #endif
351 
352 #endif
353 
354 #if defined( MBG_TGT_LINUX ) \
355  || defined( MBG_TGT_BSD ) \
356  || defined( MBG_TGT_QNX_NTO ) \
357  || defined( MBG_TGT_SUNOS )
358 
359  #define MBG_TGT_POSIX
360  #define MBG_TGT_UNIX
361 
362 #endif
363 
364 #if defined( MBG_TGT_WIN32 )
365 
366  #if !defined( _CRT_SECURE_NO_WARNINGS )
367  #define _CRT_SECURE_NO_WARNINGS 1
368  #endif
369 
370  #include <limits.h>
371 
372  #define MBG_TGT_HAS_DEV_FN 1
373  #define MBG_TGT_HAS_DEV_FN_BASE 0
374  #define MBG_TGT_USE_IOCTL 1
375 
376 #endif
377 
378 
379 // Some definitions depending on the build environment ...
380 
381 #define FUNC_UNKNOWN "func_???"
382 
383 #if defined( __GNUC__ ) || defined( __clang__ )
384 
385  #if defined( __clang__ )
386  #define _CLANG_VERSION ( __clang_major__ * 10000 \
387  + __clang_minor__ * 100 \
388  + __clang_patchlevel__ )
389  #endif // defined( __clang__ )
390 
391  #define _GCC_VERSION ( __GNUC__ * 10000 \
392  + __GNUC_MINOR__ * 100 \
393  + __GNUC_PATCHLEVEL__ )
394 
395  #if defined( __MINGW32__ )
396  #define MBG_TGT_MINGW
397  #endif
398 
399  #if defined( __MINGW64__ )
400  #define MBG_TGT_MINGW
401  #endif
402 
403  #if defined( MBG_TGT_MINGW ) && defined( __MINGW_EXTENSION )
404  // MSYS2 / MinGW defines __MINGW_EXTENSION
405  // and provides _abs64() and some other stuff,
406  // but the standard MinGW environment does not.
407  #if !defined( MBG_TGT_HAS_ABS64 )
408  #define MBG_TGT_HAS_ABS64 1
409  #endif
410  #endif
411 
412  #if defined( __i386__ )
413 
414  #define MBG_ARCH_I386
415  #define MBG_ARCH_X86
416 
417  #elif defined( __x86_64__ )
418 
419  #define MBG_ARCH_X86_64
420  #define MBG_ARCH_X86
421 
422  #elif defined( __ia64__ )
423 
424  #define MBG_ARCH_IA64
425 
426  #define _NO_USE_PACK_INTF
427 
428  #elif defined( __sparc__ )
429 
430  #define MBG_ARCH_SPARC
431 
432  #define _NO_USE_PACK_INTF
433 
434  #elif defined( __arm__ )
435 
436  #define MBG_ARCH_ARM
437 
438  #endif
439 
440  #if defined( MBG_TGT_LINUX )
441 
442  #if defined( MBG_TGT_KERNEL )
443 
444  #include <linux/types.h>
445  #include <linux/version.h>
446 
447  #if ( LINUX_VERSION_CODE <= KERNEL_VERSION( 2, 6, 4 ) ) || \
448  ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 4 ) ) // must be true for 2.6.32-5-sparc64
449  #define _ULONG_DEFINED 1
450  #define _USHORT_DEFINED 1
451  #define _UINT_DEFINED 1
452  #endif
453 
454  // The 'bool' type is supported by the vanilla Linux kernel 2.6.19 and later.
455  #if ( LINUX_VERSION_CODE < KERNEL_VERSION( 2, 6, 19 ) )
456 
457  // However, looks like at least the RedHat folks have backported this
458  // to 2.6.18, so KERNEL_HAS_BOOL can be defined to avoid a compiler error
459  // due to a duplicate definition.
460  #if !defined( KERNEL_HAS_BOOL )
461  typedef _Bool bool;
462  #define bool bool
463  #endif
464 
465  // Similar for 'true' and 'false'.
466  #if !defined( KERNEL_HAS_TRUE_FALSE )
467  enum
468  {
469  false,
470  true
471  };
472  #define falso false
473  #define true true
474  #endif
475 
476  #endif
477 
478  // The 'uintptr_t' type has been introduced
479  // after v2.6.24-rc1 and before v2.6.24-rc2.
480  #if ( LINUX_VERSION_CODE < KERNEL_VERSION( 2, 6, 24 ) )
481  typedef unsigned long uintptr_t;
482  #define uintptr_t uintptr_t
483  #endif
484 
485  // String formatter codes like "PRIi64" for int64_t types
486  // don't seem to be defined in Linux kernel mode, so we
487  // define the required "ll" or "l" modifier here as a hack.
488  // Code below uses this to define appropriate "PRIi64"-like
489  // definitions as "lli" or "li".
490  #if !defined( MBG_PRI_64_PREFIX )
491  // Please note that e.g. Linux 2.6.16 on Itanium (ia64)
492  // with gcc 4.1.2 expects "%li" to print an int64_t.
493  // This may be a bug in the specific gcc version, though.
494  #define MBG_PRI_64_PREFIX "ll"
495  #endif
496 
497  #else
498 
499  #include <stdint.h>
500  #include <inttypes.h>
501  #include <stdbool.h>
502 
503  #if defined( __u_char_defined )
504  #define _ULONG_DEFINED 1
505  #define _USHORT_DEFINED 1
506  #define _UINT_DEFINED 1
507  #endif
508 
509  #endif
510 
511  #define MBG_TGT_HAS_DEV_FN 1
512  #define MBG_TGT_HAS_DEV_FN_BASE 1
513  #define MBG_TGT_USE_IOCTL 1
514 
515  #elif defined( MBG_TGT_BSD )
516 
517  #if defined( MBG_TGT_KERNEL )
518  #include <sys/types.h>
519  #else
520  #include <stdint.h>
521  #include <inttypes.h>
522  #include <stdbool.h>
523  #endif
524 
525  #define MBG_TGT_HAS_DEV_FN 1
526  #define MBG_TGT_HAS_DEV_FN_BASE 1
527  #define MBG_TGT_USE_IOCTL 1
528 
529  #if defined( MBG_TGT_FREEBSD ) && defined( MBG_TGT_KERNEL )
530  #if !defined( MBG_PRI_64_PREFIX )
531  // String formatter codes like "PRIi64" for int64_t types
532  // don't seem to be defined in FreeBSD kernel mode, so we
533  // define the required "ll" or "l" modifier here as a hack.
534  // Code below uses this to define appropriate "PRIi64"-like
535  // definitions as "lli" or "li".
536  #define MBG_PRI_64_PREFIX "l"
537  #endif
538  #endif
539 
540  #elif defined( MBG_TGT_QNX_NTO ) // QNX 6.x (Neutrino)
541 
542  #include <unistd.h>
543  #include <stdint.h>
544  #include <inttypes.h>
545  #include <stdbool.h>
546 
547  #else
548 
549  #include <stdint.h>
550  #include <inttypes.h>
551  #include <stdbool.h>
552 
553  #endif
554 
555  #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1
556 
557  #define MBG_TGT_HAS_WCHAR_T 1
558 
559 
560  #if defined( __clang__ )
561  #define _DEPRECATED_BY( _s ) __attribute__((deprecated("use \"" _s "\" instead"))) // works with clang 3.4.1
562  #elif ( _GCC_VERSION > 40500 ) // gcc 4.5.0 and newer
563  #define _DEPRECATED_BY( _s ) __attribute__((deprecated("use \"" _s "\" instead")))
564  #elif ( _GCC_VERSION > 30100 ) // gcc 3.1 and newer
565  #define _DEPRECATED_BY( _s ) __attribute__((deprecated))
566  #else
567  // Not supported at all, use empty default definiton below.
568  #endif
569 
570  #if ( _GCC_VERSION > 30100 ) // gcc 3.1 and newer
571  #define __mbg_inline __inline__ __attribute__((always_inline))
572  #else
573  // Not supported at all, use empty default definiton below.
574  #define __mbg_inline __inline__
575  #endif
576 
577 #elif defined( _MSC_VER )
578 
579  // Known predifined MS compiler version codes:
580  // 1910: MSVC++ 15.0 (Visual Studio 2017)
581  // 1900: MSVC++ 14.0 (Visual Studio 2015)
582  // 1800: MSVC++ 12.0 (Visual Studio 2013)
583  // 1700: MSVC++ 11.0 (Visual Studio 2012)
584  // 1600: MSVC++ 10.0 (Visual Studio 2010)
585  // 1500: MSVC++ 9.0 (Visual Studio 2008)
586  // 1400: MSVC++ 8.0 (Visual Studio 2005, Windows Server 2003 SP1 DDK - AMD64)
587  // 1310: MSVC++ 7.1 (Visual Studio .NET 2003, Windows Server 2003 DDK)
588  // 1300: MSVC++ 7.0 (Visual Studio .NET 2002, Windows XP SP1 DDK / DDK 2600)
589  // 1200: MSVC++ 6.0
590  // 1100: MSVC++ 5.0
591 
592  // Enable this to get compile-time messages on the compiler version
593  #if 0
594  #if ( _MSC_VER >= 1910 )
595  #error >= 1910: MSVC++ 15.0 (Visual Studio 2017), or later
596  #elif ( _MSC_VER >= 1900 )
597  #error 1900: MSVC++ 14.0 (Visual Studio 2015)
598  #elif ( _MSC_VER >= 1800 )
599  #error 1800: MSVC++ 12.0 (Visual Studio 2013)
600  #elif ( _MSC_VER >= 1700 )
601  #error 1700: MSVC++ 11.0 (Visual Studio 2012)
602  #elif ( _MSC_VER >= 1600 )
603  #error 1600: MSVC++ 10.0 (Visual Studio 2010)
604  #elif ( _MSC_VER >= 1500 )
605  #error 1500: MSVC++ 9.0 (Visual Studio 2008)
606  #elif ( _MSC_VER >= 1400 )
607  #error STRINGIFY( _MSC_VER ) MSVC++ 8.0 (Visual Studio 2005, Windows Server 2003 SP1 DDK - AMD64)
608  #elif ( _MSC_VER >= 1310 )
609  #error 1310: MSVC++ 7.1 (Visual Studio .NET 2003, Windows Server 2003 DDK)
610  #elif ( _MSC_VER >= 1300 )
611  #error 1300: MSVC++ 7.0 (Visual Studio .NET 2002, Windows XP SP1 DDK / DDK 2600)
612  #elif ( _MSC_VER >= 1200 )
613  #error 1200: MSVC++ 6.0
614  #elif ( _MSC_VER >= 1100 )
615  #error 1100: MSVC++ 5.0
616  #else
617  #error <1100: Older than MSVC 4
618  #endif
619  #endif
620 
621  // "struct timespec" is supported only since VS2015
622  // If it is then also the symbol TIME_UTC should be defined.
623  // Functions to read the current time as struct timespec
624  // are timespec_get() and friends, which are also only provided
625  // by VS2015 and later.
626  // As of VS2015, only TIME_UTC is supported to read
627  // the UTC system time, there is no equivalent for
628  // the POSIX CLOCK_MONOTONIC. However, QPC can be used
629  // to get monotonic time stamps and intervals.
630  #if ( _MSC_VER < 1900 )
631  #if !defined( HAVE_STRUCT_TIMESPEC )
632  #define MBG_TGT_MISSING_STRUCT_TIMESPEC 1
633  #endif
634  #endif
635 
636  #if ( _MSC_VER >= 1600 ) // TODO Eventually even 1600 doesn't support this.
637  #include <stdint.h>
638  #include <inttypes.h>
639  #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1
640 
641  #if !defined( PRId64 )
642  #define MBG_PRI_64_PREFIX "I64"
643  #endif
644  #else
645  #define MBG_TGT_HAS_INT_8_16_32 1
646  #define MBG_PRI_64_PREFIX "I64"
647  #endif
648 
649  #if !defined( __cplusplus )
650  // no bool support anyway
651  #define MBG_TGT_MISSING_BOOL_TYPE 1
652  #endif
653 
654  #define MBG_TGT_HAS_WCHAR_T 1
655 
656  #define __mbg_inline __forceinline
657 
658  // At least up to VS2008 the C99 builtin symbol __func__
659  // is not supported. Some VS versions support __FUNCTION__
660  // instead, but at least VC6 doesn't support this, either.
661  // of the current function instead.
662  #if ( _MSC_VER >= 1300 )
663  #define __func__ __FUNCTION__
664  #else
665  #define __func__ FUNC_UNKNOWN
666  #endif
667 
668  // The "deprecated" attribute should be supported since Visual Studio 2005,
669  // but doesn't seem to be supported e.g. by the compiler shipped with the
670  // "Windows Server 2003 SP1 DDK", which is used to build kernel drivers
671  // and defines the same _MSC_VER number as VS2005. For now we assume
672  // that this is supported by compilers shipped with newer DDKs.
673  // The _DDK_BUILD_ symbol has to be explicitly defined in the "sources"
674  // file of the DDK project.
675  #if ( ( _MSC_VER >= 1500 ) || \
676  ( ( _MSC_VER >= 1400 ) && !defined( _DDK_BUILD_ ) ) )
677  #define _DEPRECATED_BY( _s ) __declspec(deprecated("deprecated, use \"" _s "\""))
678  #endif
679 
680  // availability of _abs64()
681  #if ( _MSC_VER >= 1310 )
682  // This is supported at least since Visual Studio 2008
683  // and Windows Server 2003 SP1 DDK.
684 
685  #if !defined( MBG_TGT_HAS_ABS64 )
686  #define MBG_TGT_HAS_ABS64 1
687  #endif
688  #endif
689 
690  #if !defined ( HAVE_SSIZE_T )
691 
692  // ssize_t support
693  #if ( _MSC_VER >= 1500 )
694  // ssize_t may not be defined, but SSIZE_T is
695  #include <basetsd.h>
696  typedef SSIZE_T ssize_t;
697  #else
698  // At least VC6 hasn't SIZE_T, either, but size_t
699  // is typedef'ed as unsigned int, so we just typedef
700  // the signed variant here.
701  typedef int ssize_t;
702  #endif
703 
704  #define HAVE_SSIZE_T 1
705 
706  #endif // !defined ( HAVE_SSIZE_T )
707 
708  #if ( _MSC_VER <= 1500 )
709  // At least MSVC++ 9.0 / Visual Studio 2008 and older
710  // don't provide lldiv_t and lldiv().
711  #define MBG_TGT_MISSING_LLDIV_T 1
712  #endif
713 
714  #if ( _MSC_VER <= 1400 )
715  #define MBG_TGT_MISSING_STRTOLL 1
716  #elif ( _MSC_VER <= 1600 )
717  // At least MSVC++ 10.0 / Visual Studio 2010 and older
718  // don't provide strtoll(), but may provide _strtoi64 instead.
719  #define strtoll _strtoi64
720  #endif
721 
722 #elif defined( _CVI_ )
723 
724  // 1000 for CVI v10.0 (CVI 2010)
725  // 911 for CVI v9.1.1 (CVI 2009 SP1)
726  // 910 for CVI v9.1 (CVI 2009)
727  // 310 for CVI v3.1
728  // 301 for CVI v3.0.1
729  // 1 for CVI v3.0
730 
731  #if ( _CVI_ >= 910 )
732  // LabWindows/CVI 2009 is the first version providing stdint.h.
733  #include <stdint.h>
734  #include <inttypes.h>
735  #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1
736  #else
737  #define USE_LONG_FOR_INT32 1
738  #endif
739 
740  // As of LabWindows/CVI 2010, stdbool.h is still missing.
741  #define MBG_TGT_MISSING_BOOL_TYPE 1
742 
743  #define MBG_TGT_HAS_WCHAR_T 0
744 
745  // Inline code is not supported, though the inline keyword
746  // is silently accepted since CVI v9.0
747 
748 #elif defined( __BORLANDC__ ) // or __CODEGEARC__ in newer versions
749 
750  // 0x0200 Borland C/C++ 2.0
751  // 0x0400 Borland C/C++ 3.0
752  // 0x0410 Borland C/C++ 3.1
753  // 0x0550 Borland C/C++ 5.5 (C++Builder 5.0)
754 
755  // Next codes are in addition defined as __CODEGEARC__
756  // See http://docwiki.embarcadero.com
757 
758  // 0x0570 for Borland Developer Studio 2006 (BDS 2006)
759  // 0x0590 for C++Builder 2007
760  // 0x0591 for update 1 to C++Builder 2007
761  // 0x0592 for RAD Studio 2007
762  // 0x0593 for the December update to RAD Studio 2007
763  // 0x0610 for C++Builder 2009 and for C++Builder 2009 Update 1
764  // 0x0620 for C++Builder 2010 and for C++Builder 2010 Update 1
765  // 0x0621 for C++Builder 2010 Update 2
766  // 0x0630 for C++Builder XE
767  // 0x0631 for C++Builder XE Update 1
768  // 0x0640 for C++Builder XE2
769  // 0x0650 for C++Builder XE3
770 
771  #if ( __BORLANDC__ >= 0x630 )
772  // C++Builder XE starts to provide stdbool.h
773  #include <stdint.h>
774  #include <inttypes.h>
775  #include <stdbool.h>
776  #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1
777  #elif ( __BORLANDC__ >= 0x570 )
778  // BDS/Borland C++ Builder 2006 starts to provide at least stdint.h
779  #include <stdint.h>
780  #include <inttypes.h>
781  #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1
782  #if !defined( __cplusplus )
783  #define MBG_TGT_MISSING_BOOL_TYPE 1
784  #endif
785  #elif ( __BORLANDC__ >= 0x0550 )
786  #define MBG_TGT_HAS_INT_8_16_32 1
787  #define MBG_PRI_64_PREFIX "I64"
788  #if !defined( __cplusplus )
789  #define MBG_TGT_MISSING_BOOL_TYPE 1
790  #endif
791  #define __func__ FUNC_UNKNOWN
792  #else // e.g. BC 3.1 or earlier
793  #if ( __BORLANDC__ <= 0x410 )
794  #define MBG_TGT_MISSING_64_BIT_TYPES 1
795  #define MBG_TGT_MISSING_BOOL_TYPE 1
796  #define USE_LONG_FOR_INT32 1
797  #define MBG_TGT_MISSING_STRUCT_TIMESPEC 1
798  #define __func__ __FILE__ ":" STRINGIFY(__LINE__)
799 
800  typedef int ssize_t;
801  #endif
802  #endif
803 
804  #if ( __BORLANDC__ <= 0x0550 )
805  // At least CBuilder 5 and earlier.
806  #define MBG_TGT_MISSING_STRTOLL 1
807  #define MBG_TGT_MISSING_LLDIV_T 1
808  #endif
809 
810  #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 )
811 
812  #define MBG_TGT_MISSING_STRUCT_TIMESPEC 1
813 
814  #if defined( __cplusplus )
815  #define __mbg_inline inline // standard C++ syntax
816  #elif ( __BORLANDC__ > 0x410 ) // BC3.1 defines 0x410 !
817  #define __mbg_inline __inline // newer BC versions support this for C
818  #else
819  #define __mbg_inline // up to BC3.1 not supported for C
820  #endif
821 
822  #if !defined ( HAVE_SSIZE_T )
823  typedef int ssize_t; // required at least for C++ Builder 5
824  #define HAVE_SSIZE_T 1
825  #endif
826 
827 #elif defined( __WATCOMC__ )
828 
829  // 1050 v10.5
830  // 1100 v11.0
831  // 1200 Open Watcom C++ v1.0
832  // 1230 Open Watcom C++ v1.3
833  // 1270 Open Watcom C++ v1.7
834 
835  #if defined( MBG_TGT_QNX ) // QNX 4.x
836 
837  #include <sys/types.h>
838 
839  #define MBG_TGT_MISSING_64_BIT_TYPES 1
840 
841  #elif ( __WATCOMC__ > 1230 ) // Open Watcom C 1.3 and above
842 
843  #include <stdint.h>
844  #include <inttypes.h>
845 
846  #elif !defined( __WATCOM_INT64__ ) // Watcom C 11
847 
848  #define MBG_TGT_MISSING_64_BIT_TYPES 1
849 
850  #endif
851 
852  #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 )
853 
854  #define __mbg_inline _inline
855 
856 #endif
857 
858 
859 #if !defined( MBG_TGT_USE_IOCTL )
860  #define MBG_TGT_USE_IOCTL 0
861 #endif
862 
863 
864 // If the build environment doesn't provide an inttypes.h file
865 // with print format specifiers for 64 bit fixed size types
866 // then MBG_PRI_64_PREFIX should be defined, which is used
867 // to define our own C99 compatible format specifiers.
868 // Eventually, similar definitions are required for 32, 16,
869 // and 8 bit fixed size types.
870 #if defined( MBG_PRI_64_PREFIX )
871  #define PRIi64 MBG_PRI_64_PREFIX "i"
872  #define PRId64 MBG_PRI_64_PREFIX "d"
873  #define PRIo64 MBG_PRI_64_PREFIX "o"
874  #define PRIu64 MBG_PRI_64_PREFIX "u"
875  #define PRIx64 MBG_PRI_64_PREFIX "x"
876  #define PRIX64 MBG_PRI_64_PREFIX "X"
877 #endif
878 
879 #if !defined( __GNUC__ ) && !defined( __attribute__ )
880  #define __attribute__( _x )
881 #endif
882 
883 #if !defined( _DEPRECATED_BY )
884  #define _DEPRECATED_BY( _s ) // empty definition
885 #endif
886 
887 
888 #if defined( MBG_TGT_WIN32 )
889 
890  #if defined( _AMD64_ )
891  // This is used for AMD64 architecture and for
892  // Intel XEON CPUs with 64 bit extension.
893  #define MBG_TGT_WIN32_PNP_X64
894  #define WIN32_FLAVOR "x64"
895  #elif defined( _IA64_ )
896  #define MBG_TGT_WIN32_PNP_IA64
897  #define WIN32_FLAVOR "ia64"
898  #endif
899 
900  #if defined( _KDD_ )
901  #define MBG_TGT_KERNEL
902 
903  #include <ntddk.h>
904 
905  #if defined( DBG ) && DBG
906  #define DEBUG 1
907  #endif
908 
909  #define _MBG_API
910  #else
911  // This must not be used for kernel drivers.
912 
913  // Prevent inclusion of obsolete winsock.h in windows.h
914  #if !defined( WIN32_LEAN_AND_MEAN )
915  #define WIN32_LEAN_AND_MEAN 1
916  #endif
917 
918  #include <winsock2.h>
919  #include <windows.h>
920  #include <ws2tcpip.h>
921 
922  typedef HANDLE MBG_HANDLE;
923 
924  #define MBG_INVALID_HANDLE INVALID_HANDLE_VALUE
925 
926  #if defined( MBG_TGT_CVI )
927  // CVI uses an own set of functions to support serial ports
928  typedef int MBG_PORT_HANDLE;
929  #define MBG_INVALID_PORT_HANDLE -1
930  #else
931  typedef HANDLE MBG_PORT_HANDLE;
932  #endif
933 
934  // The DWORD_PTR type is not defined in the headers shipping
935  // with VC6. However, if the SDK is installed then the SDK's
936  // headers may declare this type. This is at least the case
937  // in the Oct 2001 SDK which also defines the symbol _W64.
938  #if !defined( _W64 )
939  typedef DWORD DWORD_PTR;
940  #endif
941 
942  // socklen_t support
943  #if ( _MSC_VER < 1500 )
944  // At least VS2008 has a socklen_t type
945  typedef int socklen_t;
946  #endif
947 
948  #define _MBG_API WINAPI
949 
950  #endif
951 
952  #if !defined( MBG_TGT_MINGW ) // not required for MinGW
953  #if defined( MBG_LIB_EXPORT )
954  #define _MBG_API_ATTR __declspec( dllexport )
955  #else
956  #define _MBG_API_ATTR __declspec( dllimport )
957  #endif
958  #endif
959 
960 #elif defined( MBG_TGT_POSIX )
961 
962  #if !defined( MBG_TGT_KERNEL )
963  #include <unistd.h>
964  #endif
965 
966  typedef int MBG_HANDLE;
967  typedef int MBG_PORT_HANDLE;
968 
969  #define MBG_INVALID_HANDLE -1
970 
971 #else
972 
973  typedef int MBG_HANDLE;
974  typedef int MBG_PORT_HANDLE;
975 
976  #define MBG_INVALID_HANDLE -1
977 
978 #endif
979 
980 
984 #if defined( MBG_TGT_WIN32 ) && !defined( MBG_TGT_MINGW )
985  #if !defined( MBG_TGT_KERNEL ) // we don't need this in kernel space
986  // usually evaluates to UINT_PTR, which in turn evaluates
987  // to (unsigned int), or (unsigned __int64).
988  typedef SOCKET MBG_SOCK_FD;
989  #endif
990 #elif defined( MBG_TGT_POSIX )
991  typedef int MBG_SOCK_FD; //### TODO
992  //### TODO typedef int SOCKET;
993 #endif
994 
995 
996 
1000 #if defined( MBG_TGT_WIN32 )
1001  #define MBG_INVALID_SOCK_FD INVALID_SOCKET // usually evaluates to (SOCKET)(~0) since SOCKET is unsigned
1002 #elif defined( MBG_TGT_POSIX )
1003  #define MBG_INVALID_SOCK_FD -1
1004 #endif
1005 
1006 
1007 
1011 #if defined( MBG_TGT_WIN32 )
1012  #define MBG_SOCKET_ERR_RETVAL SOCKET_ERROR // usually evaluates to -1
1013 #elif defined( MBG_TGT_POSIX )
1014  #define MBG_SOCKET_ERR_RETVAL -1
1015 #endif
1016 
1017 
1018 
1019 #if !defined( _MBG_API )
1020  #define _MBG_API
1021 #endif
1022 
1023 #if !defined( _MBG_API_ATTR )
1024  #define _MBG_API_ATTR
1025 #endif
1026 
1027 #if !defined( _NO_MBG_API )
1028  #define _NO_MBG_API
1029 #endif
1030 
1031 #if !defined( _NO_MBG_API_ATTR )
1032  #define _NO_MBG_API_ATTR
1033 #endif
1034 
1035 #if !defined( MBG_INVALID_PORT_HANDLE )
1036  #define MBG_INVALID_PORT_HANDLE MBG_INVALID_HANDLE
1037 #endif
1038 
1039 #if !defined( MBG_TGT_HAS_DEV_FN )
1040  #define MBG_TGT_HAS_DEV_FN 0
1041 #endif
1042 
1043 #if !defined( MBG_TGT_HAS_DEV_FN_BASE )
1044  #define MBG_TGT_HAS_DEV_FN_BASE 0
1045 #endif
1046 
1047 #if defined( MBG_TGT_MISSING_STRUCT_TIMESPEC )
1048 
1049  #include <time.h>
1050 
1051  struct timespec
1052  {
1053  time_t tv_sec;
1054  long tv_nsec;
1055  };
1056 
1057 #endif // defined( MBG_TGT_MISSING_STRUCT_TIMESPEC )
1058 
1059 
1060 // The macros below are defined in order to be able to check if
1061 // certain C language extensions are available on the target system:
1062 #if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199409L )
1063  #define MBG_TGT_C94 1
1064 #else
1065  #define MBG_TGT_C94 0
1066 #endif
1067 
1068 
1069 #if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L )
1070  #define MBG_TGT_C99 1
1071 #else
1072  #define MBG_TGT_C99 0
1073 #endif
1074 
1075 // Check if wchar_t is supported
1076 #if !defined( MBG_TGT_HAS_WCHAR_T )
1077  #define MBG_TGT_HAS_WCHAR_T ( MBG_TGT_C94 || defined( WCHAR_MAX ) )
1078 #endif
1079 
1080 #if !MBG_TGT_HAS_WCHAR_T
1081  // Even if wchar_t is not natively supported by the target platform
1082  // there may already be a compatibility define (e.g. BC3.1)
1083  // However, some functions may be missing (e.g. snwprintf()).
1084  #if !defined( _WCHAR_T ) /* BC3.1 */ \
1085  && !defined( _WCHAR_T_DEFINED_ ) /* WC11 */
1086  #define _WCHAR_T
1087  #define wchar_t char
1088  #endif
1089 #endif
1090 
1091 
1092 
1093 /* ----- function prototypes begin ----- */
1094 
1095 /* This section was generated automatically */
1096 /* by MAKEHDR, do not remove the comments. */
1097 
1098 /* (no header definitions found) */
1099 
1100 /* ----- function prototypes end ----- */
1101 
1102 #ifdef __cplusplus
1103 }
1104 #endif
1105 
1106 /* End of header body */
1107 
1108 #undef _ext
1109 
1110 #endif // !defined( MBG_TGT_NO_TGT )
1111 
1112 #endif // !defined( _MBG_TGT_H )
int MBG_PORT_HANDLE
Definition: mbg_tgt.h:967
int bool
Definition: words.h:370
int MBG_SOCK_FD
A socket file descriptor type.
Definition: mbg_tgt.h:991
int MBG_HANDLE
Definition: mbg_tgt.h:966
uint32_t DWORD
Definition: mbgerror.h:222