Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / asn_system.h
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 #                                                                            *
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                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
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.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 /*
20  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21  * Redistribution and modifications are permitted subject to BSD license.
22  */
23 /*
24  * Miscellaneous system-dependent types.
25  */
26 #ifndef ASN_SYSTEM_H
27 #define ASN_SYSTEM_H
28
29 #ifdef  HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #ifndef _DEFAULT_SOURCE
34 #define _DEFAULT_SOURCE 1
35 #endif
36
37 #ifndef _BSD_SOURCE
38 #define _BSD_SOURCE /* for snprintf() on some linux systems  */
39 #endif
40
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 */
48
49 #ifdef  _WIN32
50
51 #include <malloc.h>
52 #define  snprintf       _snprintf
53 #define  vsnprintf      _vsnprintf
54
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)        \
59                         | ((l >> 24) & 0xff))
60
61 #ifdef _MSC_VER                 /* MSVS.Net */
62 #ifndef __cplusplus
63 #define inline __inline
64 #endif
65 #ifndef ASSUMESTDTYPES  /* Standard types have been defined elsewhere */
66 #define ssize_t         SSIZE_T
67 #if _MSC_VER < 1600
68 typedef char            int8_t;
69 typedef short           int16_t;
70 typedef int             int32_t;
71 typedef unsigned char   uint8_t;
72 typedef unsigned short  uint16_t;
73 typedef unsigned int    uint32_t;
74 #else /* _MSC_VER >= 1600 */
75 #include <stdint.h>
76 #endif /* _MSC_VER < 1600 */
77 #endif  /* ASSUMESTDTYPES */
78 #define WIN32_LEAN_AND_MEAN
79 #include <windows.h>
80 #include <float.h>
81 #define isnan _isnan
82 #define finite _finite
83 #define copysign _copysign
84 #define ilogb   _logb
85 #else   /* !_MSC_VER */
86 #include <stdint.h>
87 #endif  /* _MSC_VER */
88
89 #else   /* !_WIN32 */
90
91 #if defined(__vxworks)
92 #include <types/vxTypes.h>
93 #else   /* !defined(__vxworks) */
94
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) */
99
100 #endif  /* _WIN32 */
101
102 #if     __GNUC__ >= 3 || defined(__clang__)
103 #define CC_ATTRIBUTE(attr)    __attribute__((attr))
104 #else
105 #define CC_ATTRIBUTE(attr)
106 #endif
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))
111 #endif
112
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 */
117
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 */
121
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__ */
129 #endif  /* MIN */
130
131 #if __STDC_VERSION__ >= 199901L
132 #ifndef SIZE_MAX
133 #define SIZE_MAX   ((~((size_t)0)) >> 1)
134 #endif
135
136 #ifndef RSIZE_MAX   /* C11, Annex K */
137 #define RSIZE_MAX   (SIZE_MAX >> 1)
138 #endif
139 #ifndef RSSIZE_MAX   /* Halve signed size even further than unsigned */
140 #define RSSIZE_MAX   ((ssize_t)(RSIZE_MAX >> 1))
141 #endif
142 #else   /* Old compiler */
143 #undef  SIZE_MAX
144 #undef  RSIZE_MAX
145 #undef  RSSIZE_MAX
146 #define SIZE_MAX   ((~((size_t)0)) >> 1)
147 #define RSIZE_MAX   (SIZE_MAX >> 1)
148 #define RSSIZE_MAX   ((ssize_t)(RSIZE_MAX >> 1))
149 #endif
150
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
156 #else
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"
162 #else
163 #define ASN_PRIuMAX "lu"
164 #define ASN_PRIdMAX "ld"
165 #endif
166 #endif
167
168 #endif  /* ASN_SYSTEM_H */