1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
5 # Licensed under the Apache License, Version 2.0 (the "License"); *
6 # you may not use this file except in compliance with the License. *
7 # You may obtain a copy of the License at *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
11 # Unless required by applicable law or agreed to in writing, software *
12 # distributed under the License is distributed on an "AS IS" BASIS, *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 # See the License for the specific language governing permissions and *
15 # limitations under the License. *
17 ******************************************************************************/
20 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
24 * Miscellaneous system-dependent types.
33 #ifndef _DEFAULT_SOURCE
34 #define _DEFAULT_SOURCE 1
38 #define _BSD_SOURCE /* for snprintf() on some linux systems */
41 #include <stdio.h> /* For snprintf(3) */
42 #include <stdlib.h> /* For *alloc(3) */
43 #include <string.h> /* For memcpy(3) */
44 #include <sys/types.h> /* For size_t */
45 #include <limits.h> /* For LONG_MAX */
46 #include <stdarg.h> /* For va_start */
47 #include <stddef.h> /* for offsetof and ptrdiff_t */
52 #define snprintf _snprintf
53 #define vsnprintf _vsnprintf
55 /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
56 #define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
57 | (((l) << 8) & 0xff0000) \
58 | (((l) >> 8) & 0xff00) \
61 #ifdef _MSC_VER /* MSVS.Net */
63 #define inline __inline
65 #ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
66 #define ssize_t SSIZE_T
69 typedef short int16_t;
71 typedef unsigned char uint8_t;
72 typedef unsigned short uint16_t;
73 typedef unsigned int uint32_t;
74 #else /* _MSC_VER >= 1600 */
76 #endif /* _MSC_VER < 1600 */
77 #endif /* ASSUMESTDTYPES */
78 #define WIN32_LEAN_AND_MEAN
82 #define finite _finite
83 #define copysign _copysign
91 #if defined(__vxworks)
92 #include <types/vxTypes.h>
93 #else /* !defined(__vxworks) */
95 #include <inttypes.h> /* C99 specifies this file */
96 #include <netinet/in.h> /* for ntohl() */
97 #define sys_ntohl(foo) ntohl(foo)
98 #endif /* defined(__vxworks) */
102 #if __GNUC__ >= 3 || defined(__clang__)
103 #define CC_ATTRIBUTE(attr) __attribute__((attr))
105 #define CC_ATTRIBUTE(attr)
107 #define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(printf, fmt, var))
108 #define CC_NOTUSED CC_ATTRIBUTE(unused)
109 #ifndef CC_ATTR_NO_SANITIZE
110 #define CC_ATTR_NO_SANITIZE(what) CC_ATTRIBUTE(no_sanitize(what))
113 /* Figure out if thread safety is requested */
114 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
115 #define ASN_THREAD_SAFE
116 #endif /* Thread safety */
118 #ifndef offsetof /* If not defined by <stddef.h> */
119 #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
120 #endif /* offsetof */
122 #ifndef MIN /* Suitable for comparing primitive types (integers) */
123 #if defined(__GNUC__)
124 #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
125 ((_a)<(_b)?(_a):(_b)); })
126 #else /* !__GNUC__ */
127 #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
128 #endif /* __GNUC__ */
131 #if __STDC_VERSION__ >= 199901L
133 #define SIZE_MAX ((~((size_t)0)) >> 1)
136 #ifndef RSIZE_MAX /* C11, Annex K */
137 #define RSIZE_MAX (SIZE_MAX >> 1)
139 #ifndef RSSIZE_MAX /* Halve signed size even further than unsigned */
140 #define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1))
142 #else /* Old compiler */
146 #define SIZE_MAX ((~((size_t)0)) >> 1)
147 #define RSIZE_MAX (SIZE_MAX >> 1)
148 #define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1))
151 #if __STDC_VERSION__ >= 199901L
152 #define ASN_PRI_SIZE "zu"
153 #define ASN_PRI_SSIZE "zd"
154 #define ASN_PRIuMAX PRIuMAX
155 #define ASN_PRIdMAX PRIdMAX
157 #define ASN_PRI_SIZE "lu"
158 #define ASN_PRI_SSIZE "ld"
159 #if LLONG_MAX > LONG_MAX
160 #define ASN_PRIuMAX "llu"
161 #define ASN_PRIdMAX "lld"
163 #define ASN_PRIuMAX "lu"
164 #define ASN_PRIdMAX "ld"
168 #endif /* ASN_SYSTEM_H */