vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003, 2004 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 | */ |
vlm | 9de248e | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 8 | #ifndef _ASN_SYSTEM_H_ |
| 9 | #define _ASN_SYSTEM_H_ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 10 | |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 11 | #ifdef HAVE_CONFIG_H |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 15 | #include <stdio.h> /* For snprintf(3) */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 16 | #include <stdlib.h> /* For *alloc(3) */ |
| 17 | #include <string.h> /* For memcpy(3) */ |
| 18 | #include <sys/types.h> /* For size_t */ |
| 19 | #include <stdarg.h> /* For va_start */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | #include <stddef.h> /* for offsetof and ptrdiff_t */ |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 21 | |
vlm | 8a09e0f | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 22 | #ifdef WIN32 |
| 23 | |
vlm | b5a6943 | 2006-05-02 18:55:41 +0000 | [diff] [blame] | 24 | #include <malloc.h> |
| 25 | #include <stdint.h> |
vlm | 8a09e0f | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 26 | #define snprintf _snprintf |
| 27 | #define vsnprintf _vsnprintf |
vlm | 8a09e0f | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 28 | |
vlm | 0b56940 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 29 | #ifdef _MSC_VER /* MSVS.Net */ |
vlm | 7c05fdf | 2005-08-17 18:39:36 +0000 | [diff] [blame] | 30 | #ifndef __cplusplus |
| 31 | #define inline __inline |
| 32 | #endif |
vlm | 0b56940 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 33 | #define ssize_t SSIZE_T |
| 34 | typedef char int8_t; |
| 35 | typedef short int16_t; |
| 36 | typedef int int32_t; |
| 37 | typedef unsigned char uint8_t; |
| 38 | typedef unsigned short uint16_t; |
| 39 | typedef unsigned int uint32_t; |
| 40 | #define WIN32_LEAN_AND_MEAN |
| 41 | #include <windows.h> |
vlm | cb4aaa7 | 2005-07-01 08:28:18 +0000 | [diff] [blame] | 42 | #include <float.h> |
| 43 | #define isnan _isnan |
| 44 | #define finite _finite |
| 45 | #define copysign _copysign |
| 46 | #define ilogb _logb |
vlm | 0b56940 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 47 | #endif /* _MSC_VER */ |
| 48 | |
vlm | 8a09e0f | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 49 | #else /* !WIN32 */ |
| 50 | |
vlm | b5a6943 | 2006-05-02 18:55:41 +0000 | [diff] [blame] | 51 | #if defined(__vxworks) |
| 52 | #include <types/vxTypes.h> |
| 53 | #else /* !defined(__vxworks) */ |
| 54 | |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 55 | #include <inttypes.h> /* C99 specifies this file */ |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 56 | /* |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 57 | * 1. Earlier FreeBSD version didn't have <stdint.h>, |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 58 | * but <inttypes.h> was present. |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 59 | * 2. Sun Solaris requires <alloca.h> for alloca(3), |
| 60 | * but does not have <stdint.h>. |
vlm | 7502143 | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 61 | */ |
vlm | 8d0d396 | 2004-10-25 22:58:35 +0000 | [diff] [blame] | 62 | #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 63 | #if defined(sun) |
| 64 | #include <alloca.h> /* For alloca(3) */ |
vlm | 8a09e0f | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 65 | #include <ieeefp.h> /* for finite(3) */ |
vlm | 9d6283e | 2006-03-16 22:29:55 +0000 | [diff] [blame] | 66 | #elif defined(__hpux) |
| 67 | #ifdef __GNUC__ |
| 68 | #include <alloca.h> /* For alloca(3) */ |
| 69 | #else /* !__GNUC__ */ |
| 70 | #define inline |
| 71 | #endif /* __GNUC__ */ |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 72 | #else |
vlm | a4294b7 | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 73 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
vlm | 8a09e0f | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 74 | #endif /* defined(sun) */ |
vlm | 6534a8d | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 75 | #endif |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 76 | |
vlm | b5a6943 | 2006-05-02 18:55:41 +0000 | [diff] [blame] | 77 | #endif /* defined(__vxworks) */ |
| 78 | |
vlm | a4294b7 | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 79 | #endif /* WIN32 */ |
vlm | 6e73a04 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 80 | |
| 81 | #ifndef __GNUC__ |
| 82 | #define __attribute__(ignore) |
| 83 | #endif |
| 84 | |
| 85 | #ifndef offsetof /* If not defined by <stddef.h> */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 86 | #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) |
| 87 | #endif /* offsetof */ |
| 88 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 89 | #ifndef MIN /* Suitable for comparing primitive types (integers) */ |
| 90 | #if defined(__GNUC__) |
| 91 | #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ |
| 92 | ((_a)<(_b)?(_a):(_b)); }) |
| 93 | #else /* !__GNUC__ */ |
| 94 | #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ |
| 95 | #endif /* __GNUC__ */ |
| 96 | #endif /* MIN */ |
| 97 | |
vlm | 9de248e | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 98 | #endif /* _ASN_SYSTEM_H_ */ |