blob: d7ebdaa4e16a2636184db6ba4fe34fda5860a6bc [file] [log] [blame]
Harald Welte92c45f32010-06-12 18:59:38 +02001/*-
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 */
8#ifndef _ASN_SYSTEM_H_
9#define _ASN_SYSTEM_H_
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include <stdio.h> /* For snprintf(3) */
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 */
20#include <stddef.h> /* for offsetof and ptrdiff_t */
21
22#ifdef WIN32
23
24#include <malloc.h>
25#include <stdint.h>
26#define snprintf _snprintf
27#define vsnprintf _vsnprintf
28
29#ifdef _MSC_VER /* MSVS.Net */
30#ifndef __cplusplus
31#define inline __inline
32#endif
33#define ssize_t SSIZE_T
34typedef char int8_t;
35typedef short int16_t;
36typedef int int32_t;
37typedef unsigned char uint8_t;
38typedef unsigned short uint16_t;
39typedef unsigned int uint32_t;
40#define WIN32_LEAN_AND_MEAN
41#include <windows.h>
42#include <float.h>
43#define isnan _isnan
44#define finite _finite
45#define copysign _copysign
46#define ilogb _logb
47#endif /* _MSC_VER */
48
49#else /* !WIN32 */
50
51#if defined(__vxworks)
52#include <types/vxTypes.h>
53#else /* !defined(__vxworks) */
54
55#include <inttypes.h> /* C99 specifies this file */
56/*
57 * 1. Earlier FreeBSD version didn't have <stdint.h>,
58 * but <inttypes.h> was present.
59 * 2. Sun Solaris requires <alloca.h> for alloca(3),
60 * but does not have <stdint.h>.
61 */
62#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
63#if defined(sun)
64#include <alloca.h> /* For alloca(3) */
65#include <ieeefp.h> /* for finite(3) */
66#elif defined(__hpux)
67#ifdef __GNUC__
68#include <alloca.h> /* For alloca(3) */
69#else /* !__GNUC__ */
70#define inline
71#endif /* __GNUC__ */
72#else
73#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
74#endif /* defined(sun) */
75#endif
76
77#endif /* defined(__vxworks) */
78
79#endif /* WIN32 */
80
81#if __GNUC__ >= 3
82#ifndef GCC_PRINTFLIKE
83#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
84#endif
85#else
86#ifndef GCC_PRINTFLIKE
87#define GCC_PRINTFLIKE(fmt,var) /* nothing */
88#endif
89#endif
90
91#ifndef offsetof /* If not defined by <stddef.h> */
92#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
93#endif /* offsetof */
94
95#ifndef MIN /* Suitable for comparing primitive types (integers) */
96#if defined(__GNUC__)
97#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
98 ((_a)<(_b)?(_a):(_b)); })
99#else /* !__GNUC__ */
100#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
101#endif /* __GNUC__ */
102#endif /* MIN */
103
104#endif /* _ASN_SYSTEM_H_ */