blob: 6dcca0eb40c2e1cd1626bddbe506c5da977240b9 [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
Lev Walkinf689f0b2006-05-02 18:55:41 +000024#include <malloc.h>
25#include <stdint.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000026#define snprintf _snprintf
27#define vsnprintf _vsnprintf
Lev Walkin4efbfb72005-02-25 14:20:30 +000028
Lev Walkin4cca5092005-05-27 20:56:08 +000029#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000030#ifndef __cplusplus
31#define inline __inline
32#endif
Lev Walkin4cca5092005-05-27 20:56:08 +000033#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>
Lev Walkin2f505022005-07-01 08:28:18 +000042#include <float.h>
43#define isnan _isnan
44#define finite _finite
45#define copysign _copysign
46#define ilogb _logb
Lev Walkin4cca5092005-05-27 20:56:08 +000047#endif /* _MSC_VER */
48
Lev Walkin4efbfb72005-02-25 14:20:30 +000049#else /* !WIN32 */
50
Lev Walkinf689f0b2006-05-02 18:55:41 +000051#if defined(__vxworks)
52#include <types/vxTypes.h>
53#else /* !defined(__vxworks) */
54
Lev Walkin0ede18c2004-09-07 10:47:39 +000055#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000056/*
Lev Walkina460ba32004-10-20 15:40:04 +000057 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000058 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000059 * 2. Sun Solaris requires <alloca.h> for alloca(3),
60 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000061 */
Lev Walkineeab25b2004-10-25 22:58:35 +000062#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000063#if defined(sun)
64#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000065#include <ieeefp.h> /* for finite(3) */
Lev Walkinfa956652006-03-16 22:29:55 +000066#elif defined(__hpux)
67#ifdef __GNUC__
68#include <alloca.h> /* For alloca(3) */
69#else /* !__GNUC__ */
70#define inline
71#endif /* __GNUC__ */
Lev Walkina460ba32004-10-20 15:40:04 +000072#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000073#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000074#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000075#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000076
Lev Walkinf689f0b2006-05-02 18:55:41 +000077#endif /* defined(__vxworks) */
78
Lev Walkin1ff369a2004-09-07 07:26:32 +000079#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000080
Lev Walkin3f6afc12006-09-15 18:52:36 +000081#if __GNUC__ >= 3
82#ifndef GCC_PRINTFLIKE
83#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
84#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +000085#ifndef GCC_NOTUSED
86#define GCC_NOTUSED __attribute__((unused))
87#endif
Lev Walkin3f6afc12006-09-15 18:52:36 +000088#else
89#ifndef GCC_PRINTFLIKE
90#define GCC_PRINTFLIKE(fmt,var) /* nothing */
91#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +000092#ifndef GCC_NOTUSED
93#define GCC_NOTUSED
94#endif
Lev Walkin64399722004-08-11 07:17:22 +000095#endif
96
97#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +000098#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
99#endif /* offsetof */
100
Lev Walkinf15320b2004-06-03 03:38:44 +0000101#ifndef MIN /* Suitable for comparing primitive types (integers) */
102#if defined(__GNUC__)
103#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
104 ((_a)<(_b)?(_a):(_b)); })
105#else /* !__GNUC__ */
106#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
107#endif /* __GNUC__ */
108#endif /* MIN */
109
Lev Walkindc06f6b2004-10-20 15:50:55 +0000110#endif /* _ASN_SYSTEM_H_ */