Harald Welte | 43ab79f | 2018-10-03 23:34:21 +0200 | [diff] [blame] | 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 | #ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */ |
| 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 | #endif /* ASSUMESTDTYPES */ |
| 49 | #define WIN32_LEAN_AND_MEAN |
| 50 | #include <windows.h> |
| 51 | #include <float.h> |
| 52 | #define isnan _isnan |
| 53 | #define finite _finite |
| 54 | #define copysign _copysign |
| 55 | #define ilogb _logb |
| 56 | #else /* !_MSC_VER */ |
| 57 | #include <stdint.h> |
| 58 | #endif /* _MSC_VER */ |
| 59 | |
| 60 | #else /* !_WIN32 */ |
| 61 | |
| 62 | #if defined(__vxworks) |
| 63 | #include <types/vxTypes.h> |
| 64 | #else /* !defined(__vxworks) */ |
| 65 | |
| 66 | #include <inttypes.h> /* C99 specifies this file */ |
| 67 | /* |
| 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>. |
| 72 | */ |
| 73 | #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) |
| 74 | #if defined(sun) |
| 75 | #include <alloca.h> /* For alloca(3) */ |
| 76 | #include <ieeefp.h> /* for finite(3) */ |
| 77 | #elif defined(__hpux) |
| 78 | #ifdef __GNUC__ |
| 79 | #include <alloca.h> /* For alloca(3) */ |
| 80 | #else /* !__GNUC__ */ |
| 81 | #define inline |
| 82 | #endif /* __GNUC__ */ |
| 83 | #else |
| 84 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
| 85 | #endif /* defined(sun) */ |
| 86 | #endif |
| 87 | |
| 88 | #include <netinet/in.h> /* for ntohl() */ |
| 89 | #define sys_ntohl(foo) ntohl(foo) |
| 90 | |
| 91 | #endif /* defined(__vxworks) */ |
| 92 | |
| 93 | #endif /* _WIN32 */ |
| 94 | |
| 95 | #if __GNUC__ >= 3 |
| 96 | #ifndef GCC_PRINTFLIKE |
| 97 | #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) |
| 98 | #endif |
| 99 | #ifndef GCC_NOTUSED |
| 100 | #define GCC_NOTUSED __attribute__((unused)) |
| 101 | #endif |
| 102 | #else |
| 103 | #ifndef GCC_PRINTFLIKE |
| 104 | #define GCC_PRINTFLIKE(fmt,var) /* nothing */ |
| 105 | #endif |
| 106 | #ifndef GCC_NOTUSED |
| 107 | #define GCC_NOTUSED |
| 108 | #endif |
| 109 | #endif |
| 110 | |
| 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 */ |
| 115 | |
| 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 */ |
| 119 | |
| 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__ */ |
| 127 | #endif /* MIN */ |
| 128 | |
| 129 | #endif /* _ASN_SYSTEM_H_ */ |