asn_system.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 /*
6  * Miscellaneous system-dependent types.
7  */
8 #ifndef ASN_SYSTEM_H
9 #define ASN_SYSTEM_H
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #ifndef _DEFAULT_SOURCE
16 #define _DEFAULT_SOURCE 1
17 #endif
18 
19 #ifndef _BSD_SOURCE
20 #define _BSD_SOURCE /* for snprintf() on some linux systems */
21 #endif
22 
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 */
30 #include <inttypes.h> /* for PRIdMAX */
31 
32 #ifdef _WIN32
33 
34 #include <malloc.h>
35 #ifndef __MINGW32__
36 #define snprintf _snprintf
37 #define vsnprintf _vsnprintf
38 #endif
39 
40 /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
41 #define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
42  | (((l) << 8) & 0xff0000) \
43  | (((l) >> 8) & 0xff00) \
44  | ((l >> 24) & 0xff))
45 
46 #ifdef _MSC_VER /* MSVS.Net */
47 #ifndef __cplusplus
48 #define inline __inline
49 #endif
50 #ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
51 #define ssize_t SSIZE_T
52 #if _MSC_VER < 1600
53 typedef char int8_t;
54 typedef short int16_t;
55 typedef int int32_t;
56 typedef unsigned char uint8_t;
57 typedef unsigned short uint16_t;
58 typedef unsigned int uint32_t;
59 #else /* _MSC_VER >= 1600 */
60 #include <stdint.h>
61 #endif /* _MSC_VER < 1600 */
62 #endif /* ASSUMESTDTYPES */
63 #define WIN32_LEAN_AND_MEAN
64 #include <windows.h>
65 #include <float.h>
66 #define isnan _isnan
67 #define finite _finite
68 #define copysign _copysign
69 #define ilogb _logb
70 #else /* !_MSC_VER */
71 #include <stdint.h>
72 #endif /* _MSC_VER */
73 
74 #else /* !_WIN32 */
75 
76 #if defined(__vxworks)
77 #include <types/vxTypes.h>
78 #else /* !defined(__vxworks) */
79 
80 #include <inttypes.h> /* C99 specifies this file */
81 #ifdef HAVE_ARPA_INET_H
82 #include <arpa/inet.h> /* for ntohl() */
83 #define sys_ntohl(foo) ntohl(foo)
84 #else /* !_HAVE_ARPA_INET_H */
85 #ifdef HAVE_NETINET_IN_H
86 #include <netinet/in.h> /* for ntohl() */
87 #define sys_ntohl(foo) ntohl(foo)
88 #else /* !_HAVE_NETINET_IN_H */
89 /* Here's the definition of ntohl() */
90 #define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
91  | (((l) << 8) & 0xff0000) \
92  | (((l) >> 8) & 0xff00) \
93  | ((l >> 24) & 0xff))
94 #endif /* HAVE_NETINET_IN_H */
95 #endif /* HAVE_ARPA_INET_H */
96 #endif /* defined(__vxworks) */
97 
98 
99 #endif /* _WIN32 */
100 
101 #if __GNUC__ >= 3 || defined(__clang__)
102 #define CC_ATTRIBUTE(attr) __attribute__((attr))
103 #else
104 #define CC_ATTRIBUTE(attr)
105 #endif
106 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4)
107 #define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(gnu_printf, fmt, var))
108 #elif defined(__GNUC__)
109 #if defined(ANDROID)
110 #define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(__format__(__printf__, fmt, var))
111 #else
112 #define CC_PRINTFLIKE(fmt, var) CC_ATTRIBUTE(format(printf, fmt, var))
113 #endif
114 #else
115 #define CC_PRINTFLIKE(fmt, var)
116 #endif
117 #define CC_NOTUSED CC_ATTRIBUTE(unused)
118 #ifndef CC_ATTR_NO_SANITIZE
119 #if __GNUC__ < 8
120 #define CC_ATTR_NO_SANITIZE(what)
121 #else
122 #define CC_ATTR_NO_SANITIZE(what) CC_ATTRIBUTE(no_sanitize(what))
123 #endif
124 #endif
125 
126 /* Figure out if thread safety is requested */
127 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
128 #define ASN_THREAD_SAFE
129 #endif /* Thread safety */
130 
131 #ifndef offsetof /* If not defined by <stddef.h> */
132 #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
133 #endif /* offsetof */
134 
135 #ifndef MIN /* Suitable for comparing primitive types (integers) */
136 #if defined(__GNUC__)
137 #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
138  ((_a)<(_b)?(_a):(_b)); })
139 #else /* !__GNUC__ */
140 #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
141 #endif /* __GNUC__ */
142 #endif /* MIN */
143 
144 #if __STDC_VERSION__ >= 199901L
145 #ifndef SIZE_MAX
146 #define SIZE_MAX ((~((size_t)0)) >> 1)
147 #endif
148 
149 #ifndef RSIZE_MAX /* C11, Annex K */
150 #define RSIZE_MAX (SIZE_MAX >> 1)
151 #endif
152 #ifndef RSSIZE_MAX /* Halve signed size even further than unsigned */
153 #define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1))
154 #endif
155 #else /* Old compiler */
156 #undef SIZE_MAX
157 #undef RSIZE_MAX
158 #undef RSSIZE_MAX
159 #define SIZE_MAX ((~((size_t)0)) >> 1)
160 #define RSIZE_MAX (SIZE_MAX >> 1)
161 #define RSSIZE_MAX ((ssize_t)(RSIZE_MAX >> 1))
162 #endif
163 
164 #if __STDC_VERSION__ >= 199901L
165 #define ASN_PRI_SIZE "zu"
166 #define ASN_PRI_SSIZE "zd"
167 #define ASN_PRIuMAX PRIuMAX
168 #define ASN_PRIdMAX PRIdMAX
169 #define ASN_PRIu64 PRIu64
170 #define ASN_PRId64 PRId64
171 #else
172 #define ASN_PRI_SIZE "lu"
173 #define ASN_PRI_SSIZE "ld"
174 #define ASN_PRIu64 "llu"
175 #define ASN_PRId64 "lld"
176 #if LLONG_MAX > LONG_MAX
177 #define ASN_PRIuMAX "llu"
178 #define ASN_PRIdMAX "lld"
179 #else
180 #define ASN_PRIuMAX "lu"
181 #define ASN_PRIdMAX "ld"
182 #endif
183 #endif
184 
185 #endif /* ASN_SYSTEM_H */


etsi_its_cam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:21:22