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