2 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
6 * Miscellaneous system-dependent types.
15 #ifndef _DEFAULT_SOURCE
16 #define _DEFAULT_SOURCE 1
20 #define _BSD_SOURCE /* for snprintf() on some linux systems */
23 #include <stdio.h> /* For snprintf(3) */
24 #include <stdlib.h> /* For *alloc(3) */
25 #include <string.h> /* For memcpy(3) */
26 #include <sys/types.h> /* For size_t */
27 #include <limits.h> /* For LONG_MAX */
28 #include <stdarg.h> /* For va_start */
29 #include <stddef.h> /* for offsetof and ptrdiff_t */
34 #define snprintf _snprintf
35 #define vsnprintf _vsnprintf
37 /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
38 #define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
39 | (((l) << 8) & 0xff0000) \
40 | (((l) >> 8) & 0xff00) \
43 #ifdef _MSC_VER /* MSVS.Net */
45 #define inline __inline
47 #ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
48 #define ssize_t SSIZE_T
51 typedef short int16_t;
53 typedef unsigned char uint8_t;
54 typedef unsigned short uint16_t;
55 typedef unsigned int uint32_t;
56 #else /* _MSC_VER >= 1600 */
58 #endif /* _MSC_VER < 1600 */
59 #endif /* ASSUMESTDTYPES */
60 #define WIN32_LEAN_AND_MEAN
64 #define finite _finite
65 #define copysign _copysign
73 #if defined(__vxworks)
74 #include <types/vxTypes.h>
75 #else /* !defined(__vxworks) */
77 #include <inttypes.h> /* C99 specifies this file */
78 #include <netinet/in.h> /* for ntohl() */
79 #define sys_ntohl(foo) ntohl(foo)
80 #endif /* defined(__vxworks) */
84 #if __GNUC__ >= 3 || defined(__clang__)
85 #define CC_ATTRIBUTE(attr) __attribute__((attr))
87 #define CC_ATTRIBUTE(attr)
89 #define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(printf, fmt, var))
90 #define CC_NOTUSED CC_ATTRIBUTE(unused)
91 #ifndef CC_ATTR_NO_SANITIZE
92 #define CC_ATTR_NO_SANITIZE(what) CC_ATTRIBUTE(no_sanitize(what))
95 /* Figure out if thread safety is requested */
96 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
97 #define ASN_THREAD_SAFE
98 #endif /* Thread safety */
100 #ifndef offsetof /* If not defined by <stddef.h> */
101 #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
102 #endif /* offsetof */
104 #ifndef MIN /* Suitable for comparing primitive types (integers) */
105 #if defined(__GNUC__)
106 #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
107 ((_a)<(_b)?(_a):(_b)); })
108 #else /* !__GNUC__ */
109 #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
110 #endif /* __GNUC__ */
113 #if __STDC_VERSION__ >= 199901L
115 #define SIZE_MAX ((~((size_t)0)) >> 1)
118 #ifndef RSIZE_MAX /* C11, Annex K */
119 #define RSIZE_MAX (SIZE_MAX >> 1)
121 #ifndef RSSIZE_MAX /* Halve signed size even further than unsigned */
122 #define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1))
124 #else /* Old compiler */
128 #define SIZE_MAX ((~((size_t)0)) >> 1)
129 #define RSIZE_MAX (SIZE_MAX >> 1)
130 #define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1))
133 #if __STDC_VERSION__ >= 199901L
134 #define ASN_PRI_SIZE "zu"
135 #define ASN_PRI_SSIZE "zd"
136 #define ASN_PRIuMAX PRIuMAX
137 #define ASN_PRIdMAX PRIdMAX
139 #define ASN_PRI_SIZE "lu"
140 #define ASN_PRI_SSIZE "ld"
141 #if LLONG_MAX > LONG_MAX
142 #define ASN_PRIuMAX "llu"
143 #define ASN_PRIdMAX "lld"
145 #define ASN_PRIuMAX "lu"
146 #define ASN_PRIdMAX "ld"
150 #endif /* ASN_SYSTEM_H */