Fix licensing issues
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / e2ap_engine / asn_system.h
1
2 /*
3  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 /*
7  * Miscellaneous system-dependent types.
8  */
9 #ifndef ASN_SYSTEM_H
10 #define ASN_SYSTEM_H
11
12 #ifdef  HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15
16 #ifndef _DEFAULT_SOURCE
17 #define _DEFAULT_SOURCE 1
18 #endif
19
20 #ifndef _BSD_SOURCE
21 #define _BSD_SOURCE /* for snprintf() on some linux systems  */
22 #endif
23
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 */
31
32 #ifdef  _WIN32
33
34 #include <malloc.h>
35 #define  snprintf       _snprintf
36 #define  vsnprintf      _vsnprintf
37
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)        \
42                         | ((l >> 24) & 0xff))
43
44 #ifdef _MSC_VER                 /* MSVS.Net */
45 #ifndef __cplusplus
46 #define inline __inline
47 #endif
48 #ifndef ASSUMESTDTYPES  /* Standard types have been defined elsewhere */
49 #define ssize_t         SSIZE_T
50 #if _MSC_VER < 1600
51 typedef char            int8_t;
52 typedef short           int16_t;
53 typedef int             int32_t;
54 typedef unsigned char   uint8_t;
55 typedef unsigned short  uint16_t;
56 typedef unsigned int    uint32_t;
57 #else /* _MSC_VER >= 1600 */
58 #include <stdint.h>
59 #endif /* _MSC_VER < 1600 */
60 #endif  /* ASSUMESTDTYPES */
61 #define WIN32_LEAN_AND_MEAN
62 #include <windows.h>
63 #include <float.h>
64 #define isnan _isnan
65 #define finite _finite
66 #define copysign _copysign
67 #define ilogb   _logb
68 #else   /* !_MSC_VER */
69 #include <stdint.h>
70 #endif  /* _MSC_VER */
71
72 #else   /* !_WIN32 */
73
74 #if defined(__vxworks)
75 #include <types/vxTypes.h>
76 #else   /* !defined(__vxworks) */
77
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) */
82
83 #endif  /* _WIN32 */
84
85 #if     __GNUC__ >= 3 || defined(__clang__)
86 #define CC_ATTRIBUTE(attr)    __attribute__((attr))
87 #else
88 #define CC_ATTRIBUTE(attr)
89 #endif
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))
94 #endif
95
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 */
100
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 */
104
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__ */
112 #endif  /* MIN */
113
114 #if __STDC_VERSION__ >= 199901L
115 #ifndef SIZE_MAX
116 #define SIZE_MAX   ((~((size_t)0)) >> 1)
117 #endif
118
119 #ifndef RSIZE_MAX   /* C11, Annex K */
120 #define RSIZE_MAX   (SIZE_MAX >> 1)
121 #endif
122 #ifndef RSSIZE_MAX   /* Halve signed size even further than unsigned */
123 #define RSSIZE_MAX   ((ssize_t)(RSIZE_MAX >> 1))
124 #endif
125 #else   /* Old compiler */
126 #undef  SIZE_MAX
127 #undef  RSIZE_MAX
128 #undef  RSSIZE_MAX
129 #define SIZE_MAX   ((~((size_t)0)) >> 1)
130 #define RSIZE_MAX   (SIZE_MAX >> 1)
131 #define RSSIZE_MAX   ((ssize_t)(RSIZE_MAX >> 1))
132 #endif
133
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
139 #else
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"
145 #else
146 #define ASN_PRIuMAX "lu"
147 #define ASN_PRIdMAX "ld"
148 #endif
149 #endif
150
151 #endif  /* ASN_SYSTEM_H */