2 * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
7 * Miscellaneous system-dependent types.
10 #define _ASN_SYSTEM_H_
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 */
27 #define snprintf _snprintf
28 #define vsnprintf _vsnprintf
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) \
36 #ifdef _MSC_VER /* MSVS.Net */
38 #define inline __inline
40 #ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
41 #define ssize_t SSIZE_T
43 typedef short int16_t;
45 typedef unsigned char uint8_t;
46 typedef unsigned short uint16_t;
47 typedef unsigned int uint32_t;
48 #endif /* ASSUMESTDTYPES */
49 #define WIN32_LEAN_AND_MEAN
53 #define finite _finite
54 #define copysign _copysign
62 #if defined(__vxworks)
63 #include <types/vxTypes.h>
64 #else /* !defined(__vxworks) */
66 #include <inttypes.h> /* C99 specifies this file */
68 * 1. Earlier FreeBSD version didn't have <stdint.h>,
69 * but <inttypes.h> was present.
70 * 2. Sun Solaris requires <alloca.h> for alloca(3),
71 * but does not have <stdint.h>.
73 #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
75 #include <alloca.h> /* For alloca(3) */
76 #include <ieeefp.h> /* for finite(3) */
79 #include <alloca.h> /* For alloca(3) */
84 #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
85 #endif /* defined(sun) */
88 #include <netinet/in.h> /* for ntohl() */
89 #define sys_ntohl(foo) ntohl(foo)
91 #endif /* defined(__vxworks) */
96 #ifndef GCC_PRINTFLIKE
97 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
100 #define GCC_NOTUSED __attribute__((unused))
103 #ifndef GCC_PRINTFLIKE
104 #define GCC_PRINTFLIKE(fmt,var) /* nothing */
111 /* Figure out if thread safety is requested */
112 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
113 #define ASN_THREAD_SAFE
114 #endif /* Thread safety */
116 #ifndef offsetof /* If not defined by <stddef.h> */
117 #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
118 #endif /* offsetof */
120 #ifndef MIN /* Suitable for comparing primitive types (integers) */
121 #if defined(__GNUC__)
122 #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
123 ((_a)<(_b)?(_a):(_b)); })
124 #else /* !__GNUC__ */
125 #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
126 #endif /* __GNUC__ */
129 #endif /* _ASN_SYSTEM_H_ */