asn_system.h 3.28 KB
Newer Older
Lev Walkin's avatar
Lev Walkin committed
1
/*-
Lev Walkin's avatar
Lev Walkin committed
2
3
 * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
 * All rights reserved.
Lev Walkin's avatar
Lev Walkin committed
4
5
6
7
8
 * Redistribution and modifications are permitted subject to BSD license.
 */
/*
 * Miscellaneous system-dependent types.
 */
Lev Walkin's avatar
Lev Walkin committed
9
10
#ifndef	_ASN_SYSTEM_H_
#define	_ASN_SYSTEM_H_
Lev Walkin's avatar
Lev Walkin committed
11

Lev Walkin's avatar
Lev Walkin committed
12
13
14
15
#ifdef	HAVE_CONFIG_H
#include "config.h"
#endif

16
#include <stdio.h>	/* For snprintf(3) */
Lev Walkin's avatar
Lev Walkin committed
17
18
19
#include <stdlib.h>	/* For *alloc(3) */
#include <string.h>	/* For memcpy(3) */
#include <sys/types.h>	/* For size_t */
20
#include <limits.h>	/* For LONG_MAX */
Lev Walkin's avatar
Lev Walkin committed
21
22
#include <stdarg.h>	/* For va_start */
#include <stddef.h>	/* for offsetof and ptrdiff_t */
Lev Walkin's avatar
Lev Walkin committed
23

24
#ifdef	_WIN32
Lev Walkin's avatar
Lev Walkin committed
25

Lev Walkin's avatar
Lev Walkin committed
26
#include <malloc.h>
Lev Walkin's avatar
Lev Walkin committed
27
28
#define	 snprintf	_snprintf
#define	 vsnprintf	_vsnprintf
29

Lev Walkin's avatar
ntohl    
Lev Walkin committed
30
/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
Lev Walkin's avatar
Lev Walkin committed
31
#define sys_ntohl(l)	((((l) << 24)  & 0xff000000)	\
32
33
34
			| (((l) << 8) & 0xff0000)	\
			| (((l) >> 8)  & 0xff00)	\
			| ((l >> 24) & 0xff))
Lev Walkin's avatar
ntohl    
Lev Walkin committed
35

Lev Walkin's avatar
Lev Walkin committed
36
#ifdef _MSC_VER			/* MSVS.Net */
Lev Walkin's avatar
Lev Walkin committed
37
38
39
#ifndef __cplusplus
#define inline __inline
#endif
Lev Walkin's avatar
Lev Walkin committed
40
#ifndef	ASSUMESTDTYPES	/* Standard types have been defined elsewhere */
Lev Walkin's avatar
Lev Walkin committed
41
42
43
44
45
46
47
#define	ssize_t		SSIZE_T
typedef	char		int8_t;
typedef	short		int16_t;
typedef	int		int32_t;
typedef	unsigned char	uint8_t;
typedef	unsigned short	uint16_t;
typedef	unsigned int	uint32_t;
Lev Walkin's avatar
Lev Walkin committed
48
#endif	/* ASSUMESTDTYPES */
Lev Walkin's avatar
Lev Walkin committed
49
#define WIN32_LEAN_AND_MEAN
Lev Walkin's avatar
Lev Walkin committed
50
#include <windows.h>
51
52
53
54
55
#include <float.h>
#define isnan _isnan
#define finite _finite
#define copysign _copysign
#define	ilogb	_logb
56
57
#else	/* !_MSC_VER */
#include <stdint.h>
Lev Walkin's avatar
Lev Walkin committed
58
59
#endif	/* _MSC_VER */

60
#else	/* !_WIN32 */
Lev Walkin's avatar
Lev Walkin committed
61

Lev Walkin's avatar
Lev Walkin committed
62
63
64
65
#if defined(__vxworks)
#include <types/vxTypes.h>
#else	/* !defined(__vxworks) */

Lev Walkin's avatar
Lev Walkin committed
66
#include <inttypes.h>	/* C99 specifies this file */
Lev Walkin's avatar
Lev Walkin committed
67
/*
68
 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin's avatar
Lev Walkin committed
69
 * but <inttypes.h> was present.
70
71
 * 2. Sun Solaris requires <alloca.h> for alloca(3),
 * but does not have <stdint.h>.
Lev Walkin's avatar
Lev Walkin committed
72
 */
Lev Walkin's avatar
Lev Walkin committed
73
#if	(!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
74
75
#if	defined(sun)
#include <alloca.h>	/* For alloca(3) */
Lev Walkin's avatar
Lev Walkin committed
76
#include <ieeefp.h>	/* for finite(3) */
Lev Walkin's avatar
Lev Walkin committed
77
78
79
80
81
82
#elif	defined(__hpux)
#ifdef	__GNUC__
#include <alloca.h>	/* For alloca(3) */
#else	/* !__GNUC__ */
#define inline
#endif	/* __GNUC__ */
83
#else
Lev Walkin's avatar
Lev Walkin committed
84
#include <stdint.h>	/* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin's avatar
Lev Walkin committed
85
#endif	/* defined(sun) */
86
#endif
Lev Walkin's avatar
Lev Walkin committed
87

Lev Walkin's avatar
ntohl    
Lev Walkin committed
88
89
90
#include <netinet/in.h> /* for ntohl() */
#define	sys_ntohl(foo)	ntohl(foo)

Lev Walkin's avatar
Lev Walkin committed
91
92
#endif	/* defined(__vxworks) */

93
#endif	/* _WIN32 */
Lev Walkin's avatar
Lev Walkin committed
94

95
96
97
98
#if	__GNUC__ >= 3
#ifndef	GCC_PRINTFLIKE
#define	GCC_PRINTFLIKE(fmt,var)	__attribute__((format(printf,fmt,var)))
#endif
Lev Walkin's avatar
Lev Walkin committed
99
100
101
#ifndef	GCC_NOTUSED
#define	GCC_NOTUSED		__attribute__((unused))
#endif
102
103
104
105
#else
#ifndef	GCC_PRINTFLIKE
#define	GCC_PRINTFLIKE(fmt,var)	/* nothing */
#endif
Lev Walkin's avatar
Lev Walkin committed
106
107
108
#ifndef	GCC_NOTUSED
#define	GCC_NOTUSED
#endif
Lev Walkin's avatar
Lev Walkin committed
109
#endif
Lev Walkin's avatar
Lev Walkin committed
110

Lev Walkin's avatar
Lev Walkin committed
111
/* Figure out if thread safety is requested */
Lev Walkin's avatar
Lev Walkin committed
112
#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
Lev Walkin's avatar
Lev Walkin committed
113
114
115
#define	ASN_THREAD_SAFE
#endif	/* Thread safety */

Lev Walkin's avatar
Lev Walkin committed
116
#ifndef	offsetof	/* If not defined by <stddef.h> */
Lev Walkin's avatar
Lev Walkin committed
117
118
119
120
121
122
123
124
125
126
127
128
#define	offsetof(s, m)	((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
#endif	/* offsetof */

#ifndef	MIN		/* Suitable for comparing primitive types (integers) */
#if defined(__GNUC__)
#define	MIN(a,b)	({ __typeof a _a = a; __typeof b _b = b;	\
	((_a)<(_b)?(_a):(_b)); })
#else	/* !__GNUC__ */
#define	MIN(a,b)	((a)<(b)?(a):(b))	/* Unsafe variant */
#endif /* __GNUC__ */
#endif	/* MIN */

Lev Walkin's avatar
Lev Walkin committed
129
#endif	/* _ASN_SYSTEM_H_ */