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 | |
| 28 | #else /* !WIN32 */ |
| 29 | |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 30 | #include <inttypes.h> /* C99 specifies this file */ |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 31 | /* |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 32 | * 1. Earlier FreeBSD version didn't have <stdint.h>, |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 33 | * but <inttypes.h> was present. |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 34 | * 2. Sun Solaris requires <alloca.h> for alloca(3), |
| 35 | * but does not have <stdint.h>. |
Lev Walkin | 0ede18c | 2004-09-07 10:47:39 +0000 | [diff] [blame] | 36 | */ |
Lev Walkin | eeab25b | 2004-10-25 22:58:35 +0000 | [diff] [blame] | 37 | #if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 38 | #if defined(sun) |
| 39 | #include <alloca.h> /* For alloca(3) */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 40 | #include <ieeefp.h> /* for finite(3) */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 41 | #else |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 42 | #include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 43 | #endif /* defined(sun) */ |
Lev Walkin | a460ba3 | 2004-10-20 15:40:04 +0000 | [diff] [blame] | 44 | #endif |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | |
Lev Walkin | 1ff369a | 2004-09-07 07:26:32 +0000 | [diff] [blame] | 46 | #endif /* WIN32 */ |
Lev Walkin | 6439972 | 2004-08-11 07:17:22 +0000 | [diff] [blame] | 47 | |
| 48 | #ifndef __GNUC__ |
| 49 | #define __attribute__(ignore) |
| 50 | #endif |
| 51 | |
| 52 | #ifndef offsetof /* If not defined by <stddef.h> */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 53 | #define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) |
| 54 | #endif /* offsetof */ |
| 55 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | #ifndef MIN /* Suitable for comparing primitive types (integers) */ |
| 57 | #if defined(__GNUC__) |
| 58 | #define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ |
| 59 | ((_a)<(_b)?(_a):(_b)); }) |
| 60 | #else /* !__GNUC__ */ |
| 61 | #define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ |
| 62 | #endif /* __GNUC__ */ |
| 63 | #endif /* MIN */ |
| 64 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 65 | #endif /* _ASN_SYSTEM_H_ */ |