Lev Walkin | f15320b | 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 | */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 8 | #ifndef _ASN_SYSTEM_H_ |
| 9 | #define _ASN_SYSTEM_H_ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 10 | |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 11 | #ifdef HAVE_CONFIG_H |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 15 | #include <stdio.h> /* For snprintf(3) */ |
Lev Walkin | f15320b | 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 */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | #include <stddef.h> /* for offsetof and ptrdiff_t */ |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 21 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 22 | #ifdef WIN32 |
| 23 | |
| 24 | #define snprintf _snprintf |
| 25 | #define vsnprintf _vsnprintf |
| 26 | #define alloca(size) _alloca(size) |
| 27 | |
Lev Walkin | 4cca509 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 28 | #ifdef _MSC_VER /* MSVS.Net */ |
| 29 | #define ssize_t SSIZE_T |
| 30 | typedef char int8_t; |
| 31 | typedef short int16_t; |
| 32 | typedef int int32_t; |
| 33 | typedef unsigned char uint8_t; |
| 34 | typedef unsigned short uint16_t; |
| 35 | typedef unsigned int uint32_t; |
| 36 | #define WIN32_LEAN_AND_MEAN |
| 37 | #include <windows.h> |
Lev Walkin | 2f50502 | 2005-07-01 08:28:18 +0000 | [diff] [blame] | 38 | #include <float.h> |
| 39 | #define isnan _isnan |
| 40 | #define finite _finite |
| 41 | #define copysign _copysign |
| 42 | #define ilogb _logb |
Lev Walkin | 4cca509 | 2005-05-27 20:56:08 +0000 | [diff] [blame] | 43 | #endif /* _MSC_VER */ |
| 44 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 45 | #else /* !WIN32 */ |
| 46 | |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 47 | #include <inttypes.h> /* C99 specifies this file */ |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 48 | /* |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 49 | * 1. Earlier FreeBSD version didn't have <stdint.h>, |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 50 | * but <inttypes.h> was present. |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 51 | * 2. Sun Solaris requires <alloca.h> for alloca(3), |
| 52 | * but does not have <stdint.h>. |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 53 | */ |
Lev Walkin | eeab25b | 2004-10-25 22:58:35 +0000 | [diff] [blame] | 54 | #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 55 | #if defined(sun) |
| 56 | #include <alloca.h> /* For alloca(3) */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 57 | #include <ieeefp.h> /* for finite(3) */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 58 | #else |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 59 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 60 | #endif /* defined(sun) */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 61 | #endif |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 63 | #endif /* WIN32 */ |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 64 | |
| 65 | #ifndef __GNUC__ |
| 66 | #define __attribute__(ignore) |
| 67 | #endif |
| 68 | |
| 69 | #ifndef offsetof /* If not defined by <stddef.h> */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 70 | #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) |
| 71 | #endif /* offsetof */ |
| 72 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 73 | #ifndef MIN /* Suitable for comparing primitive types (integers) */ |
| 74 | #if defined(__GNUC__) |
| 75 | #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ |
| 76 | ((_a)<(_b)?(_a):(_b)); }) |
| 77 | #else /* !__GNUC__ */ |
| 78 | #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ |
| 79 | #endif /* __GNUC__ */ |
| 80 | #endif /* MIN */ |
| 81 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 82 | #endif /* _ASN_SYSTEM_H_ */ |