blob: 2f4d7980db2cb9aa79c31fa8fba895da19560c8a [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
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 Walkindc06f6b2004-10-20 15:50:55 +00008#ifndef _ASN_SYSTEM_H_
9#define _ASN_SYSTEM_H_
Lev Walkinf15320b2004-06-03 03:38:44 +000010
Lev Walkin0ede18c2004-09-07 10:47:39 +000011#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
Lev Walkina460ba32004-10-20 15:40:04 +000015#include <stdio.h> /* For snprintf(3) */
Lev Walkinf15320b2004-06-03 03:38:44 +000016#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 Walkinf15320b2004-06-03 03:38:44 +000020#include <stddef.h> /* for offsetof and ptrdiff_t */
Lev Walkinfc776432005-03-29 17:21:14 +000021#ifndef __NO_ASSERT_H__
22#include <assert.h> /* for assert() macro */
23#endif
Lev Walkin0ede18c2004-09-07 10:47:39 +000024
Lev Walkin4efbfb72005-02-25 14:20:30 +000025#ifdef WIN32
26
27#define snprintf _snprintf
28#define vsnprintf _vsnprintf
29#define alloca(size) _alloca(size)
30
31#else /* !WIN32 */
32
Lev Walkin0ede18c2004-09-07 10:47:39 +000033#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000034/*
Lev Walkina460ba32004-10-20 15:40:04 +000035 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000036 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000037 * 2. Sun Solaris requires <alloca.h> for alloca(3),
38 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000039 */
Lev Walkineeab25b2004-10-25 22:58:35 +000040#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000041#if defined(sun)
42#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000043#include <ieeefp.h> /* for finite(3) */
Lev Walkina460ba32004-10-20 15:40:04 +000044#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000045#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000046#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000047#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000048
Lev Walkin1ff369a2004-09-07 07:26:32 +000049#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000050
51#ifndef __GNUC__
52#define __attribute__(ignore)
53#endif
54
55#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +000056#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
57#endif /* offsetof */
58
Lev Walkinf15320b2004-06-03 03:38:44 +000059#ifndef MIN /* Suitable for comparing primitive types (integers) */
60#if defined(__GNUC__)
61#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
62 ((_a)<(_b)?(_a):(_b)); })
63#else /* !__GNUC__ */
64#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
65#endif /* __GNUC__ */
66#endif /* MIN */
67
Lev Walkindc06f6b2004-10-20 15:50:55 +000068#endif /* _ASN_SYSTEM_H_ */