blob: a9c4ad3c9dbbce58ad379bae4c3729649179369c [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 Walkinc6cac8e2016-03-14 02:57:07 -07009#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) */
Lev Walkin19a21182016-03-14 04:15:32 -070018#include <alloca.h> /* For alloca(3) */
Lev Walkinf15320b2004-06-03 03:38:44 +000019#include <string.h> /* For memcpy(3) */
20#include <sys/types.h> /* For size_t */
Lev Walkin5c879db2007-11-06 06:23:31 +000021#include <limits.h> /* For LONG_MAX */
Lev Walkinf15320b2004-06-03 03:38:44 +000022#include <stdarg.h> /* For va_start */
Lev Walkinf15320b2004-06-03 03:38:44 +000023#include <stddef.h> /* for offsetof and ptrdiff_t */
Lev Walkin0ede18c2004-09-07 10:47:39 +000024
Lev Walkin93659562010-11-20 09:47:13 -080025#ifdef _WIN32
Lev Walkin4efbfb72005-02-25 14:20:30 +000026
Lev Walkinf689f0b2006-05-02 18:55:41 +000027#include <malloc.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000028#define snprintf _snprintf
29#define vsnprintf _vsnprintf
Lev Walkin4efbfb72005-02-25 14:20:30 +000030
Lev Walkin217f2402006-11-21 10:38:50 +000031/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
Lev Walkin349e8472006-11-27 13:31:35 +000032#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
Ilya Basin762747c2012-12-01 14:38:00 +040033 | (((l) << 8) & 0xff0000) \
34 | (((l) >> 8) & 0xff00) \
35 | ((l >> 24) & 0xff))
Lev Walkin217f2402006-11-21 10:38:50 +000036
Lev Walkin4cca5092005-05-27 20:56:08 +000037#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000038#ifndef __cplusplus
39#define inline __inline
40#endif
Lev Walkin8e391912007-11-13 23:32:38 +000041#ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
Lev Walkin4cca5092005-05-27 20:56:08 +000042#define ssize_t SSIZE_T
43typedef char int8_t;
44typedef short int16_t;
45typedef int int32_t;
46typedef unsigned char uint8_t;
47typedef unsigned short uint16_t;
48typedef unsigned int uint32_t;
Lev Walkin8e391912007-11-13 23:32:38 +000049#endif /* ASSUMESTDTYPES */
Lev Walkin05c81b72010-11-27 17:08:12 -080050#define WIN32_LEAN_AND_MEAN
Lev Walkin4cca5092005-05-27 20:56:08 +000051#include <windows.h>
Lev Walkin2f505022005-07-01 08:28:18 +000052#include <float.h>
53#define isnan _isnan
54#define finite _finite
55#define copysign _copysign
56#define ilogb _logb
Lev Walkin7943c302007-11-13 05:09:35 +000057#else /* !_MSC_VER */
58#include <stdint.h>
Lev Walkin4cca5092005-05-27 20:56:08 +000059#endif /* _MSC_VER */
60
Lev Walkin93659562010-11-20 09:47:13 -080061#else /* !_WIN32 */
Lev Walkin4efbfb72005-02-25 14:20:30 +000062
Lev Walkinf689f0b2006-05-02 18:55:41 +000063#if defined(__vxworks)
64#include <types/vxTypes.h>
65#else /* !defined(__vxworks) */
66
Lev Walkin0ede18c2004-09-07 10:47:39 +000067#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000068/*
Lev Walkina460ba32004-10-20 15:40:04 +000069 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000070 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000071 * 2. Sun Solaris requires <alloca.h> for alloca(3),
72 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000073 */
Lev Walkineeab25b2004-10-25 22:58:35 +000074#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000075#if defined(sun)
76#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000077#include <ieeefp.h> /* for finite(3) */
Lev Walkinfa956652006-03-16 22:29:55 +000078#elif defined(__hpux)
79#ifdef __GNUC__
80#include <alloca.h> /* For alloca(3) */
81#else /* !__GNUC__ */
82#define inline
83#endif /* __GNUC__ */
Lev Walkina460ba32004-10-20 15:40:04 +000084#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000085#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000086#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000087#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000088
Lev Walkin217f2402006-11-21 10:38:50 +000089#include <netinet/in.h> /* for ntohl() */
90#define sys_ntohl(foo) ntohl(foo)
91
Lev Walkinf689f0b2006-05-02 18:55:41 +000092#endif /* defined(__vxworks) */
93
Lev Walkin93659562010-11-20 09:47:13 -080094#endif /* _WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000095
Lev Walkin3f6afc12006-09-15 18:52:36 +000096#if __GNUC__ >= 3
97#ifndef GCC_PRINTFLIKE
98#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
99#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000100#ifndef GCC_NOTUSED
101#define GCC_NOTUSED __attribute__((unused))
102#endif
Lev Walkin3f6afc12006-09-15 18:52:36 +0000103#else
104#ifndef GCC_PRINTFLIKE
105#define GCC_PRINTFLIKE(fmt,var) /* nothing */
106#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000107#ifndef GCC_NOTUSED
108#define GCC_NOTUSED
109#endif
Lev Walkin64399722004-08-11 07:17:22 +0000110#endif
111
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000112/* Figure out if thread safety is requested */
Lev Walkin27f53bc2007-06-29 12:10:50 +0000113#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000114#define ASN_THREAD_SAFE
115#endif /* Thread safety */
116
Lev Walkin64399722004-08-11 07:17:22 +0000117#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +0000118#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
119#endif /* offsetof */
120
Lev Walkinf15320b2004-06-03 03:38:44 +0000121#ifndef MIN /* Suitable for comparing primitive types (integers) */
122#if defined(__GNUC__)
123#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
124 ((_a)<(_b)?(_a):(_b)); })
125#else /* !__GNUC__ */
126#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
127#endif /* __GNUC__ */
128#endif /* MIN */
129
Lev Walkinc6cac8e2016-03-14 02:57:07 -0700130#endif /* ASN_SYSTEM_H */