ITS
asn_system.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
3  * 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 #include <stdio.h> /* For snprintf(3) */
17 #include <stdlib.h> /* For *alloc(3) */
18 #include <string.h> /* For memcpy(3) */
19 #include <sys/types.h> /* For size_t */
20 #include <limits.h> /* For LONG_MAX */
21 #include <stdarg.h> /* For va_start */
22 #include <stddef.h> /* for offsetof and ptrdiff_t */
23 
24 #ifdef _WIN32
25 
26 #include <malloc.h>
27 #define snprintf _snprintf
28 #define vsnprintf _vsnprintf
29 
30 /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
31 #define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
32  | (((l) << 8) & 0xff0000) \
33  | (((l) >> 8) & 0xff00) \
34  | ((l >> 24) & 0xff))
35 
36 #ifdef _MSC_VER /* MSVS.Net */
37 #ifndef __cplusplus
38 #define inline __inline
39 #endif
40 #include <stdint.h>
41 #define ssize_t SSIZE_T
42 //typedef char int8_t;
43 //typedef short int16_t;
44 //typedef int int32_t;
45 //typedef unsigned char uint8_t;
46 //typedef unsigned short uint16_t;
47 //typedef unsigned int uint32_t;
48 #define WIN32_LEAN_AND_MEAN
49 #include <windows.h>
50 #include <float.h>
51 #define isnan _isnan
52 #define finite _finite
53 #define copysign _copysign
54 #else /* !_MSC_VER */
55 #include <stdint.h>
56 #endif /* _MSC_VER */
57 
58 #else /* !_WIN32 */
59 
60 #if defined(__vxworks)
61 #include <types/vxTypes.h>
62 #else /* !defined(__vxworks) */
63 
64 #include <inttypes.h> /* C99 specifies this file */
65 /*
66  * 1. Earlier FreeBSD version didn't have <stdint.h>,
67  * but <inttypes.h> was present.
68  * 2. Sun Solaris requires <alloca.h> for alloca(3),
69  * but does not have <stdint.h>.
70  */
71 #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
72 #if defined(sun)
73 #include <alloca.h> /* For alloca(3) */
74 #include <ieeefp.h> /* for finite(3) */
75 #elif defined(__hpux)
76 #ifdef __GNUC__
77 #include <alloca.h> /* For alloca(3) */
78 #else /* !__GNUC__ */
79 #define inline
80 #endif /* __GNUC__ */
81 #else
82 #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
83 #endif /* defined(sun) */
84 #endif
85 
86 #include <netinet/in.h> /* for ntohl() */
87 #define sys_ntohl(foo) ntohl(foo)
88 
89 #endif /* defined(__vxworks) */
90 
91 #endif /* _WIN32 */
92 
93 #if __GNUC__ >= 3
94 #ifndef GCC_PRINTFLIKE
95 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
96 #endif
97 #ifndef GCC_NOTUSED
98 #define GCC_NOTUSED __attribute__((unused))
99 #endif
100 #else
101 #ifndef GCC_PRINTFLIKE
102 #define GCC_PRINTFLIKE(fmt,var) /* nothing */
103 #endif
104 #ifndef GCC_NOTUSED
105 #define GCC_NOTUSED
106 #endif
107 #endif
108 
109 /* Figure out if thread safety is requested */
110 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
111 #define ASN_THREAD_SAFE
112 #endif /* Thread safety */
113 
114 #ifndef offsetof /* If not defined by <stddef.h> */
115 #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
116 #endif /* offsetof */
117 
118 #ifndef MIN /* Suitable for comparing primitive types (integers) */
119 #if defined(__GNUC__)
120 #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
121  ((_a)<(_b)?(_a):(_b)); })
122 #else /* !__GNUC__ */
123 #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
124 #endif /* __GNUC__ */
125 #endif /* MIN */
126 
127 #endif /* _ASN_SYSTEM_H_ */