blob: 0a9b092c3081b87e1009a240f58ea9d78557eb6b [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
vlmd97308e2007-06-29 11:38:57 +00002 * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
vlmfa67ddc2004-06-03 03:38:44 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
6/*
7 * Miscellaneous system-dependent types.
8 */
vlm9de248e2004-10-20 15:50:55 +00009#ifndef _ASN_SYSTEM_H_
10#define _ASN_SYSTEM_H_
vlmfa67ddc2004-06-03 03:38:44 +000011
vlm75021432004-09-07 10:47:39 +000012#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
vlm6534a8d2004-10-20 15:40:04 +000016#include <stdio.h> /* For snprintf(3) */
vlmfa67ddc2004-06-03 03:38:44 +000017#include <stdlib.h> /* For *alloc(3) */
18#include <string.h> /* For memcpy(3) */
19#include <sys/types.h> /* For size_t */
vlmb6053b42007-11-06 06:23:31 +000020#include <limits.h> /* For LONG_MAX */
vlmfa67ddc2004-06-03 03:38:44 +000021#include <stdarg.h> /* For va_start */
vlmfa67ddc2004-06-03 03:38:44 +000022#include <stddef.h> /* for offsetof and ptrdiff_t */
vlm75021432004-09-07 10:47:39 +000023
vlm8a09e0f2005-02-25 14:20:30 +000024#ifdef WIN32
25
vlmb5a69432006-05-02 18:55:41 +000026#include <malloc.h>
vlm8a09e0f2005-02-25 14:20:30 +000027#define snprintf _snprintf
28#define vsnprintf _vsnprintf
vlm8a09e0f2005-02-25 14:20:30 +000029
vlm7d398392006-11-21 10:38:50 +000030/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
vlm0a885a62006-11-27 13:31:35 +000031#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
32 | (((l) << 16) & 0xff0000) \
33 | (((l) << 8) & 0xff00) \
vlm7d398392006-11-21 10:38:50 +000034 | ((l) & 0xff))
35
vlm0b569402005-05-27 20:56:08 +000036#ifdef _MSC_VER /* MSVS.Net */
vlm7c05fdf2005-08-17 18:39:36 +000037#ifndef __cplusplus
38#define inline __inline
39#endif
vlm1f8c3e02007-11-13 23:32:38 +000040#ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
vlm0b569402005-05-27 20:56:08 +000041#define ssize_t SSIZE_T
42typedef char int8_t;
43typedef short int16_t;
44typedef int int32_t;
45typedef unsigned char uint8_t;
46typedef unsigned short uint16_t;
47typedef unsigned int uint32_t;
vlm1f8c3e02007-11-13 23:32:38 +000048#endif /* ASSUMESTDTYPES */
vlm0b569402005-05-27 20:56:08 +000049#define WIN32_LEAN_AND_MEAN
50#include <windows.h>
vlmcb4aaa72005-07-01 08:28:18 +000051#include <float.h>
52#define isnan _isnan
53#define finite _finite
54#define copysign _copysign
55#define ilogb _logb
vlmbbccfff2007-11-13 05:09:35 +000056#else /* !_MSC_VER */
57#include <stdint.h>
vlm0b569402005-05-27 20:56:08 +000058#endif /* _MSC_VER */
59
vlm8a09e0f2005-02-25 14:20:30 +000060#else /* !WIN32 */
61
vlmb5a69432006-05-02 18:55:41 +000062#if defined(__vxworks)
63#include <types/vxTypes.h>
64#else /* !defined(__vxworks) */
65
vlm75021432004-09-07 10:47:39 +000066#include <inttypes.h> /* C99 specifies this file */
vlm75021432004-09-07 10:47:39 +000067/*
vlm6534a8d2004-10-20 15:40:04 +000068 * 1. Earlier FreeBSD version didn't have <stdint.h>,
vlm75021432004-09-07 10:47:39 +000069 * but <inttypes.h> was present.
vlm6534a8d2004-10-20 15:40:04 +000070 * 2. Sun Solaris requires <alloca.h> for alloca(3),
71 * but does not have <stdint.h>.
vlm75021432004-09-07 10:47:39 +000072 */
vlm8d0d3962004-10-25 22:58:35 +000073#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
vlm6534a8d2004-10-20 15:40:04 +000074#if defined(sun)
75#include <alloca.h> /* For alloca(3) */
vlm8a09e0f2005-02-25 14:20:30 +000076#include <ieeefp.h> /* for finite(3) */
vlm9d6283e2006-03-16 22:29:55 +000077#elif defined(__hpux)
78#ifdef __GNUC__
79#include <alloca.h> /* For alloca(3) */
80#else /* !__GNUC__ */
81#define inline
82#endif /* __GNUC__ */
vlm6534a8d2004-10-20 15:40:04 +000083#else
vlma4294b72004-09-07 07:26:32 +000084#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
vlm8a09e0f2005-02-25 14:20:30 +000085#endif /* defined(sun) */
vlm6534a8d2004-10-20 15:40:04 +000086#endif
vlmfa67ddc2004-06-03 03:38:44 +000087
vlm7d398392006-11-21 10:38:50 +000088#include <netinet/in.h> /* for ntohl() */
89#define sys_ntohl(foo) ntohl(foo)
90
vlmb5a69432006-05-02 18:55:41 +000091#endif /* defined(__vxworks) */
92
vlma4294b72004-09-07 07:26:32 +000093#endif /* WIN32 */
vlm6e73a042004-08-11 07:17:22 +000094
vlm8a463242006-09-15 18:52:36 +000095#if __GNUC__ >= 3
96#ifndef GCC_PRINTFLIKE
97#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
98#endif
vlmef073172006-10-16 12:01:36 +000099#ifndef GCC_NOTUSED
100#define GCC_NOTUSED __attribute__((unused))
101#endif
vlm8a463242006-09-15 18:52:36 +0000102#else
103#ifndef GCC_PRINTFLIKE
104#define GCC_PRINTFLIKE(fmt,var) /* nothing */
105#endif
vlmef073172006-10-16 12:01:36 +0000106#ifndef GCC_NOTUSED
107#define GCC_NOTUSED
108#endif
vlm6e73a042004-08-11 07:17:22 +0000109#endif
110
vlmd97308e2007-06-29 11:38:57 +0000111/* Figure out if thread safety is requested */
vlmbed38dd2007-06-29 12:10:50 +0000112#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
vlmd97308e2007-06-29 11:38:57 +0000113#define ASN_THREAD_SAFE
114#endif /* Thread safety */
115
vlm6e73a042004-08-11 07:17:22 +0000116#ifndef offsetof /* If not defined by <stddef.h> */
vlmfa67ddc2004-06-03 03:38:44 +0000117#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
118#endif /* offsetof */
119
vlmfa67ddc2004-06-03 03:38:44 +0000120#ifndef MIN /* Suitable for comparing primitive types (integers) */
121#if defined(__GNUC__)
122#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
123 ((_a)<(_b)?(_a):(_b)); })
124#else /* !__GNUC__ */
125#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
126#endif /* __GNUC__ */
127#endif /* MIN */
128
vlm9de248e2004-10-20 15:50:55 +0000129#endif /* _ASN_SYSTEM_H_ */