blob: 39a1f9e60ea3f7be1c46ca50ea4fe77c1ce038c0 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin3e86a4e2007-06-29 11:38:57 +00002 * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
6/*
7 * Miscellaneous system-dependent types.
8 */
Lev Walkindc06f6b2004-10-20 15:50:55 +00009#ifndef _ASN_SYSTEM_H_
10#define _ASN_SYSTEM_H_
Lev Walkinf15320b2004-06-03 03:38:44 +000011
Lev Walkin0ede18c2004-09-07 10:47:39 +000012#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
Lev Walkina460ba32004-10-20 15:40:04 +000016#include <stdio.h> /* For snprintf(3) */
Lev Walkinf15320b2004-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 */
Lev Walkin5c879db2007-11-06 06:23:31 +000020#include <limits.h> /* For LONG_MAX */
Lev Walkinf15320b2004-06-03 03:38:44 +000021#include <stdarg.h> /* For va_start */
Lev Walkinf15320b2004-06-03 03:38:44 +000022#include <stddef.h> /* for offsetof and ptrdiff_t */
Lev Walkin0ede18c2004-09-07 10:47:39 +000023
Lev Walkin4efbfb72005-02-25 14:20:30 +000024#ifdef WIN32
25
Lev Walkinf689f0b2006-05-02 18:55:41 +000026#include <malloc.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000027#define snprintf _snprintf
28#define vsnprintf _vsnprintf
Lev Walkin4efbfb72005-02-25 14:20:30 +000029
Lev Walkin217f2402006-11-21 10:38:50 +000030/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
Lev Walkin349e8472006-11-27 13:31:35 +000031#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
32 | (((l) << 16) & 0xff0000) \
33 | (((l) << 8) & 0xff00) \
Lev Walkin217f2402006-11-21 10:38:50 +000034 | ((l) & 0xff))
35
Lev Walkin4cca5092005-05-27 20:56:08 +000036#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000037#ifndef __cplusplus
38#define inline __inline
39#endif
Lev Walkin4cca5092005-05-27 20:56:08 +000040#define ssize_t SSIZE_T
41typedef char int8_t;
42typedef short int16_t;
43typedef int int32_t;
44typedef unsigned char uint8_t;
45typedef unsigned short uint16_t;
46typedef unsigned int uint32_t;
47#define WIN32_LEAN_AND_MEAN
48#include <windows.h>
Lev Walkin2f505022005-07-01 08:28:18 +000049#include <float.h>
50#define isnan _isnan
51#define finite _finite
52#define copysign _copysign
53#define ilogb _logb
Lev Walkin7943c302007-11-13 05:09:35 +000054#else /* !_MSC_VER */
55#include <stdint.h>
Lev Walkin4cca5092005-05-27 20:56:08 +000056#endif /* _MSC_VER */
57
Lev Walkin4efbfb72005-02-25 14:20:30 +000058#else /* !WIN32 */
59
Lev Walkinf689f0b2006-05-02 18:55:41 +000060#if defined(__vxworks)
61#include <types/vxTypes.h>
62#else /* !defined(__vxworks) */
63
Lev Walkin0ede18c2004-09-07 10:47:39 +000064#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000065/*
Lev Walkina460ba32004-10-20 15:40:04 +000066 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000067 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000068 * 2. Sun Solaris requires <alloca.h> for alloca(3),
69 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000070 */
Lev Walkineeab25b2004-10-25 22:58:35 +000071#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000072#if defined(sun)
73#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000074#include <ieeefp.h> /* for finite(3) */
Lev Walkinfa956652006-03-16 22:29:55 +000075#elif defined(__hpux)
76#ifdef __GNUC__
77#include <alloca.h> /* For alloca(3) */
78#else /* !__GNUC__ */
79#define inline
80#endif /* __GNUC__ */
Lev Walkina460ba32004-10-20 15:40:04 +000081#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000082#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000083#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000084#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000085
Lev Walkin217f2402006-11-21 10:38:50 +000086#include <netinet/in.h> /* for ntohl() */
87#define sys_ntohl(foo) ntohl(foo)
88
Lev Walkinf689f0b2006-05-02 18:55:41 +000089#endif /* defined(__vxworks) */
90
Lev Walkin1ff369a2004-09-07 07:26:32 +000091#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000092
Lev Walkin3f6afc12006-09-15 18:52:36 +000093#if __GNUC__ >= 3
94#ifndef GCC_PRINTFLIKE
95#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
96#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +000097#ifndef GCC_NOTUSED
98#define GCC_NOTUSED __attribute__((unused))
99#endif
Lev Walkin3f6afc12006-09-15 18:52:36 +0000100#else
101#ifndef GCC_PRINTFLIKE
102#define GCC_PRINTFLIKE(fmt,var) /* nothing */
103#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000104#ifndef GCC_NOTUSED
105#define GCC_NOTUSED
106#endif
Lev Walkin64399722004-08-11 07:17:22 +0000107#endif
108
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000109/* Figure out if thread safety is requested */
Lev Walkin27f53bc2007-06-29 12:10:50 +0000110#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000111#define ASN_THREAD_SAFE
112#endif /* Thread safety */
113
Lev Walkin64399722004-08-11 07:17:22 +0000114#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +0000115#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
116#endif /* offsetof */
117
Lev Walkinf15320b2004-06-03 03:38:44 +0000118#ifndef MIN /* Suitable for comparing primitive types (integers) */
119#if defined(__GNUC__)
120#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
121 ((_a)<(_b)?(_a):(_b)); })
122#else /* !__GNUC__ */
123#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
124#endif /* __GNUC__ */
125#endif /* MIN */
126
Lev Walkindc06f6b2004-10-20 15:50:55 +0000127#endif /* _ASN_SYSTEM_H_ */