blob: d969e38be76f28f40c4d489df88c62f815f25661 [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 Walkin0ede18c2004-09-07 10:47:39 +000021
Lev Walkin4efbfb72005-02-25 14:20:30 +000022#ifdef WIN32
23
24#define snprintf _snprintf
25#define vsnprintf _vsnprintf
26#define alloca(size) _alloca(size)
27
Lev Walkin4cca5092005-05-27 20:56:08 +000028#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000029#ifndef __cplusplus
30#define inline __inline
31#endif
Lev Walkin4cca5092005-05-27 20:56:08 +000032#define ssize_t SSIZE_T
33typedef char int8_t;
34typedef short int16_t;
35typedef int int32_t;
36typedef unsigned char uint8_t;
37typedef unsigned short uint16_t;
38typedef unsigned int uint32_t;
39#define WIN32_LEAN_AND_MEAN
40#include <windows.h>
Lev Walkin2f505022005-07-01 08:28:18 +000041#include <float.h>
42#define isnan _isnan
43#define finite _finite
44#define copysign _copysign
45#define ilogb _logb
Lev Walkin4cca5092005-05-27 20:56:08 +000046#endif /* _MSC_VER */
47
Lev Walkin4efbfb72005-02-25 14:20:30 +000048#else /* !WIN32 */
49
Lev Walkin0ede18c2004-09-07 10:47:39 +000050#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000051/*
Lev Walkina460ba32004-10-20 15:40:04 +000052 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000053 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000054 * 2. Sun Solaris requires <alloca.h> for alloca(3),
55 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000056 */
Lev Walkineeab25b2004-10-25 22:58:35 +000057#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000058#if defined(sun)
59#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000060#include <ieeefp.h> /* for finite(3) */
Lev Walkina460ba32004-10-20 15:40:04 +000061#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000062#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000063#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000064#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000065
Lev Walkin1ff369a2004-09-07 07:26:32 +000066#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000067
68#ifndef __GNUC__
69#define __attribute__(ignore)
70#endif
71
72#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +000073#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
74#endif /* offsetof */
75
Lev Walkinf15320b2004-06-03 03:38:44 +000076#ifndef MIN /* Suitable for comparing primitive types (integers) */
77#if defined(__GNUC__)
78#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
79 ((_a)<(_b)?(_a):(_b)); })
80#else /* !__GNUC__ */
81#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
82#endif /* __GNUC__ */
83#endif /* MIN */
84
Lev Walkindc06f6b2004-10-20 15:50:55 +000085#endif /* _ASN_SYSTEM_H_ */