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

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

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

Lev Walkin's avatar
Lev Walkin committed
25
#ifdef	WIN32
Lev Walkin's avatar
Lev Walkin committed
26

Lev Walkin's avatar
Lev Walkin committed
27
28
29
#define	 snprintf	_snprintf
#define	 vsnprintf	_vsnprintf
#define	alloca(size)	_alloca(size)
30

Lev Walkin's avatar
Lev Walkin committed
31
32
33
#else	/* !WIN32 */

#include <inttypes.h>	/* C99 specifies this file */
Lev Walkin's avatar
Lev Walkin committed
34
/*
35
 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin's avatar
Lev Walkin committed
36
 * but <inttypes.h> was present.
37
38
 * 2. Sun Solaris requires <alloca.h> for alloca(3),
 * but does not have <stdint.h>.
Lev Walkin's avatar
Lev Walkin committed
39
 */
Lev Walkin's avatar
Lev Walkin committed
40
#if	(!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
41
42
#if	defined(sun)
#include <alloca.h>	/* For alloca(3) */
Lev Walkin's avatar
Lev Walkin committed
43
#include <ieeefp.h>	/* for finite(3) */
44
#else
Lev Walkin's avatar
Lev Walkin committed
45
#include <stdint.h>	/* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin's avatar
Lev Walkin committed
46
#endif	/* defined(sun) */
47
#endif
Lev Walkin's avatar
Lev Walkin committed
48

Lev Walkin's avatar
Lev Walkin committed
49
#endif	/* WIN32 */
Lev Walkin's avatar
Lev Walkin committed
50
51
52
53

#ifndef	__GNUC__
#define	__attribute__(ignore)
#endif
Lev Walkin's avatar
Lev Walkin committed
54

Lev Walkin's avatar
Lev Walkin committed
55
#ifndef	offsetof	/* If not defined by <stddef.h> */
Lev Walkin's avatar
Lev Walkin committed
56
57
58
59
60
61
62
63
64
65
66
67
#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
68
#endif	/* _ASN_SYSTEM_H_ */