modified installation guide
[ric-app/rc.git] / e2ap / headers / asn_system.h
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
31 #ifdef  _WIN32
32
33 #include <malloc.h>
34 #define  snprintf       _snprintf
35 #define  vsnprintf      _vsnprintf
36
37 /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
38 #define sys_ntohl(l)    ((((l) << 24)  & 0xff000000)    \
39                         | (((l) << 8) & 0xff0000)       \
40                         | (((l) >> 8)  & 0xff00)        \
41                         | ((l >> 24) & 0xff))
42
43 #ifdef _MSC_VER                 /* MSVS.Net */
44 #ifndef __cplusplus
45 #define inline __inline
46 #endif
47 #ifndef ASSUMESTDTYPES  /* Standard types have been defined elsewhere */
48 #define ssize_t         SSIZE_T
49 #if _MSC_VER < 1600
50 typedef char            int8_t;
51 typedef short           int16_t;
52 typedef int             int32_t;
53 typedef unsigned char   uint8_t;
54 typedef unsigned short  uint16_t;
55 typedef unsigned int    uint32_t;
56 #else /* _MSC_VER >= 1600 */
57 #include <stdint.h>
58 #endif /* _MSC_VER < 1600 */
59 #endif  /* ASSUMESTDTYPES */
60 #define WIN32_LEAN_AND_MEAN
61 #include <windows.h>
62 #include <float.h>
63 #define isnan _isnan
64 #define finite _finite
65 #define copysign _copysign
66 #ifdef WIN32    //MCHECK
67         #define ilogb   ilogb
68 #else
69         #define ilogb _logb
70 #endif
71 #else   /* !_MSC_VER */
72 #include <stdint.h>
73 #endif  /* _MSC_VER */
74
75 #else   /* !_WIN32 */
76
77 #if defined(__vxworks)
78 #include <types/vxTypes.h>
79 #else   /* !defined(__vxworks) */
80
81 #include <inttypes.h>   /* C99 specifies this file */
82 #include <netinet/in.h> /* for ntohl() */
83 #define sys_ntohl(foo)  ntohl(foo)
84 #endif  /* defined(__vxworks) */
85
86 #endif  /* _WIN32 */
87
88 #if     __GNUC__ >= 3 || defined(__clang__)
89 #define CC_ATTRIBUTE(attr)    __attribute__((attr))
90 #else
91 #define CC_ATTRIBUTE(attr)
92 #endif
93 #define CC_PRINTFLIKE(fmt, var)     CC_ATTRIBUTE(format(printf, fmt, var))
94 #define CC_NOTUSED                  CC_ATTRIBUTE(unused)
95 #ifndef CC_ATTR_NO_SANITIZE
96 #define CC_ATTR_NO_SANITIZE(what)   CC_ATTRIBUTE(no_sanitize(what))
97 #endif
98
99 /* Figure out if thread safety is requested */
100 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
101 #define ASN_THREAD_SAFE
102 #endif  /* Thread safety */
103
104 #ifndef offsetof        /* If not defined by <stddef.h> */
105 #define offsetof(s, m)  ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
106 #endif  /* offsetof */
107
108 #ifndef MIN             /* Suitable for comparing primitive types (integers) */
109 #if defined(__GNUC__)
110 #define MIN(a,b)        ({ __typeof a _a = a; __typeof b _b = b;        \
111         ((_a)<(_b)?(_a):(_b)); })
112 #else   /* !__GNUC__ */
113 #define MIN(a,b)        ((a)<(b)?(a):(b))       /* Unsafe variant */
114 #endif /* __GNUC__ */
115 #endif  /* MIN */
116
117 #if __STDC_VERSION__ >= 199901L
118 #ifndef SIZE_MAX
119 #define SIZE_MAX   ((~((size_t)0)) >> 1)
120 #endif
121
122 #ifndef RSIZE_MAX   /* C11, Annex K */
123 #define RSIZE_MAX   (SIZE_MAX >> 1)
124 #endif
125 #ifndef RSSIZE_MAX   /* Halve signed size even further than unsigned */
126 #define RSSIZE_MAX   ((ssize_t)(RSIZE_MAX >> 1))
127 #endif
128 #else   /* Old compiler */
129 #undef  SIZE_MAX
130 #undef  RSIZE_MAX
131 #undef  RSSIZE_MAX
132 #define SIZE_MAX   ((~((size_t)0)) >> 1)
133 #define RSIZE_MAX   (SIZE_MAX >> 1)
134 #define RSSIZE_MAX   ((ssize_t)(RSIZE_MAX >> 1))
135 #endif
136
137 #if __STDC_VERSION__ >= 199901L
138 #define ASN_PRI_SIZE "zu"
139 #define ASN_PRI_SSIZE "zd"
140 #define ASN_PRIuMAX PRIuMAX
141 #define ASN_PRIdMAX PRIdMAX
142 #else
143 #define ASN_PRI_SIZE "lu"
144 #define ASN_PRI_SSIZE "ld"
145 #if LLONG_MAX > LONG_MAX
146 #define ASN_PRIuMAX "llu"
147 #define ASN_PRIdMAX "lld"
148 #else
149 #define ASN_PRIuMAX "lu"
150 #define ASN_PRIdMAX "ld"
151 #endif
152 #endif
153
154 #endif  /* ASN_SYSTEM_H */