Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 3e86a4e | 2007-06-29 11:38:57 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>. |
| 3 | * All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | * Redistribution and modifications are permitted subject to BSD license. |
| 5 | */ |
| 6 | /* |
| 7 | * Miscellaneous system-dependent types. |
| 8 | */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 9 | #ifndef _ASN_SYSTEM_H_ |
| 10 | #define _ASN_SYSTEM_H_ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 12 | #ifdef HAVE_CONFIG_H |
| 13 | #include "config.h" |
| 14 | #endif |
| 15 | |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 16 | #include <stdio.h> /* For snprintf(3) */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | #include <stdlib.h> /* For *alloc(3) */ |
| 18 | #include <string.h> /* For memcpy(3) */ |
| 19 | #include <sys/types.h> /* For size_t */ |
| 20 | #include <stdarg.h> /* For va_start */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 21 | #include <stddef.h> /* for offsetof and ptrdiff_t */ |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 22 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 23 | #ifdef WIN32 |
| 24 | |
Lev Walkin | f689f0b | 2006-05-02 18:55:41 +0000 | [diff] [blame] | 25 | #include <malloc.h> |
| 26 | #include <stdint.h> |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 27 | #define snprintf _snprintf |
| 28 | #define vsnprintf _vsnprintf |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 29 | |
Lev Walkin | 217f240 | 2006-11-21 10:38:50 +0000 | [diff] [blame] | 30 | /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */ |
Lev Walkin | 349e847 | 2006-11-27 13:31:35 +0000 | [diff] [blame] | 31 | #define sys_ntohl(l) ((((l) << 24) & 0xff000000) \ |
| 32 | | (((l) << 16) & 0xff0000) \ |
| 33 | | (((l) << 8) & 0xff00) \ |
Lev Walkin | 217f240 | 2006-11-21 10:38:50 +0000 | [diff] [blame] | 34 | | ((l) & 0xff)) |
| 35 | |
Lev Walkin | 4cca509 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 36 | #ifdef _MSC_VER /* MSVS.Net */ |
Lev Walkin | e44ea0b | 2005-08-17 18:39:36 +0000 | [diff] [blame] | 37 | #ifndef __cplusplus |
| 38 | #define inline __inline |
| 39 | #endif |
Lev Walkin | 4cca509 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 40 | #define ssize_t SSIZE_T |
| 41 | typedef char int8_t; |
| 42 | typedef short int16_t; |
| 43 | typedef int int32_t; |
| 44 | typedef unsigned char uint8_t; |
| 45 | typedef unsigned short uint16_t; |
| 46 | typedef unsigned int uint32_t; |
| 47 | #define WIN32_LEAN_AND_MEAN |
| 48 | #include <windows.h> |
Lev Walkin | 2f50502 | 2005-07-01 08:28:18 +0000 | [diff] [blame] | 49 | #include <float.h> |
| 50 | #define isnan _isnan |
| 51 | #define finite _finite |
| 52 | #define copysign _copysign |
| 53 | #define ilogb _logb |
Lev Walkin | 4cca509 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 54 | #endif /* _MSC_VER */ |
| 55 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 56 | #else /* !WIN32 */ |
| 57 | |
Lev Walkin | f689f0b | 2006-05-02 18:55:41 +0000 | [diff] [blame] | 58 | #if defined(__vxworks) |
| 59 | #include <types/vxTypes.h> |
| 60 | #else /* !defined(__vxworks) */ |
| 61 | |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 62 | #include <inttypes.h> /* C99 specifies this file */ |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 63 | /* |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 64 | * 1. Earlier FreeBSD version didn't have <stdint.h>, |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 65 | * but <inttypes.h> was present. |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 66 | * 2. Sun Solaris requires <alloca.h> for alloca(3), |
| 67 | * but does not have <stdint.h>. |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 68 | */ |
Lev Walkin | eeab25b | 2004-10-25 22:58:35 +0000 | [diff] [blame] | 69 | #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 70 | #if defined(sun) |
| 71 | #include <alloca.h> /* For alloca(3) */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 72 | #include <ieeefp.h> /* for finite(3) */ |
Lev Walkin | fa95665 | 2006-03-16 22:29:55 +0000 | [diff] [blame] | 73 | #elif defined(__hpux) |
| 74 | #ifdef __GNUC__ |
| 75 | #include <alloca.h> /* For alloca(3) */ |
| 76 | #else /* !__GNUC__ */ |
| 77 | #define inline |
| 78 | #endif /* __GNUC__ */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 79 | #else |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 80 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 81 | #endif /* defined(sun) */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 82 | #endif |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 83 | |
Lev Walkin | 217f240 | 2006-11-21 10:38:50 +0000 | [diff] [blame] | 84 | #include <netinet/in.h> /* for ntohl() */ |
| 85 | #define sys_ntohl(foo) ntohl(foo) |
| 86 | |
Lev Walkin | f689f0b | 2006-05-02 18:55:41 +0000 | [diff] [blame] | 87 | #endif /* defined(__vxworks) */ |
| 88 | |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 89 | #endif /* WIN32 */ |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 90 | |
Lev Walkin | 3f6afc1 | 2006-09-15 18:52:36 +0000 | [diff] [blame] | 91 | #if __GNUC__ >= 3 |
| 92 | #ifndef GCC_PRINTFLIKE |
| 93 | #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) |
| 94 | #endif |
Lev Walkin | 50b0f6c | 2006-10-16 12:01:36 +0000 | [diff] [blame] | 95 | #ifndef GCC_NOTUSED |
| 96 | #define GCC_NOTUSED __attribute__((unused)) |
| 97 | #endif |
Lev Walkin | 3f6afc1 | 2006-09-15 18:52:36 +0000 | [diff] [blame] | 98 | #else |
| 99 | #ifndef GCC_PRINTFLIKE |
| 100 | #define GCC_PRINTFLIKE(fmt,var) /* nothing */ |
| 101 | #endif |
Lev Walkin | 50b0f6c | 2006-10-16 12:01:36 +0000 | [diff] [blame] | 102 | #ifndef GCC_NOTUSED |
| 103 | #define GCC_NOTUSED |
| 104 | #endif |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
Lev Walkin | 3e86a4e | 2007-06-29 11:38:57 +0000 | [diff] [blame] | 107 | /* Figure out if thread safety is requested */ |
Lev Walkin | 27f53bc | 2007-06-29 12:10:50 +0000 | [diff] [blame] | 108 | #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT)) |
Lev Walkin | 3e86a4e | 2007-06-29 11:38:57 +0000 | [diff] [blame] | 109 | #define ASN_THREAD_SAFE |
| 110 | #endif /* Thread safety */ |
| 111 | |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 112 | #ifndef offsetof /* If not defined by <stddef.h> */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 113 | #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) |
| 114 | #endif /* offsetof */ |
| 115 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 116 | #ifndef MIN /* Suitable for comparing primitive types (integers) */ |
| 117 | #if defined(__GNUC__) |
| 118 | #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ |
| 119 | ((_a)<(_b)?(_a):(_b)); }) |
| 120 | #else /* !__GNUC__ */ |
| 121 | #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ |
| 122 | #endif /* __GNUC__ */ |
| 123 | #endif /* MIN */ |
| 124 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 125 | #endif /* _ASN_SYSTEM_H_ */ |