blob: 24d8da798464d15373bc61af8d4c12f585e58b37 [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) */
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 Walkin619f0cd2016-07-02 19:55:23 +000024#ifdef HAVE_ALLOCA_H
25#include <alloca.h> /* For alloca(3) */
26#endif
27
Lev Walkin93659562010-11-20 09:47:13 -080028#ifdef _WIN32
Lev Walkin4efbfb72005-02-25 14:20:30 +000029
Lev Walkinf689f0b2006-05-02 18:55:41 +000030#include <malloc.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000031#define snprintf _snprintf
32#define vsnprintf _vsnprintf
Lev Walkin4efbfb72005-02-25 14:20:30 +000033
Lev Walkin217f2402006-11-21 10:38:50 +000034/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
Lev Walkin349e8472006-11-27 13:31:35 +000035#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
Ilya Basin762747c2012-12-01 14:38:00 +040036 | (((l) << 8) & 0xff0000) \
37 | (((l) >> 8) & 0xff00) \
38 | ((l >> 24) & 0xff))
Lev Walkin217f2402006-11-21 10:38:50 +000039
Lev Walkin4cca5092005-05-27 20:56:08 +000040#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000041#ifndef __cplusplus
42#define inline __inline
43#endif
Lev Walkin8e391912007-11-13 23:32:38 +000044#ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
Lev Walkin4cca5092005-05-27 20:56:08 +000045#define ssize_t SSIZE_T
46typedef char int8_t;
47typedef short int16_t;
48typedef int int32_t;
49typedef unsigned char uint8_t;
50typedef unsigned short uint16_t;
51typedef unsigned int uint32_t;
Lev Walkin8e391912007-11-13 23:32:38 +000052#endif /* ASSUMESTDTYPES */
Lev Walkin05c81b72010-11-27 17:08:12 -080053#define WIN32_LEAN_AND_MEAN
Lev Walkin4cca5092005-05-27 20:56:08 +000054#include <windows.h>
Lev Walkin2f505022005-07-01 08:28:18 +000055#include <float.h>
56#define isnan _isnan
57#define finite _finite
58#define copysign _copysign
59#define ilogb _logb
Lev Walkin7943c302007-11-13 05:09:35 +000060#else /* !_MSC_VER */
61#include <stdint.h>
Lev Walkin4cca5092005-05-27 20:56:08 +000062#endif /* _MSC_VER */
63
Lev Walkin93659562010-11-20 09:47:13 -080064#else /* !_WIN32 */
Lev Walkin4efbfb72005-02-25 14:20:30 +000065
Lev Walkinf689f0b2006-05-02 18:55:41 +000066#if defined(__vxworks)
67#include <types/vxTypes.h>
68#else /* !defined(__vxworks) */
69
Lev Walkin0ede18c2004-09-07 10:47:39 +000070#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000071/*
Lev Walkina460ba32004-10-20 15:40:04 +000072 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000073 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000074 * 2. Sun Solaris requires <alloca.h> for alloca(3),
75 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000076 */
Lev Walkineeab25b2004-10-25 22:58:35 +000077#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000078#if defined(sun)
79#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000080#include <ieeefp.h> /* for finite(3) */
Lev Walkinfa956652006-03-16 22:29:55 +000081#elif defined(__hpux)
82#ifdef __GNUC__
83#include <alloca.h> /* For alloca(3) */
84#else /* !__GNUC__ */
85#define inline
86#endif /* __GNUC__ */
Lev Walkina460ba32004-10-20 15:40:04 +000087#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000088#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000089#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000090#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000091
Lev Walkin217f2402006-11-21 10:38:50 +000092#include <netinet/in.h> /* for ntohl() */
93#define sys_ntohl(foo) ntohl(foo)
94
Lev Walkinf689f0b2006-05-02 18:55:41 +000095#endif /* defined(__vxworks) */
96
Lev Walkin93659562010-11-20 09:47:13 -080097#endif /* _WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000098
Lev Walkin3f6afc12006-09-15 18:52:36 +000099#if __GNUC__ >= 3
100#ifndef GCC_PRINTFLIKE
101#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
102#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000103#ifndef GCC_NOTUSED
104#define GCC_NOTUSED __attribute__((unused))
105#endif
Lev Walkin3f6afc12006-09-15 18:52:36 +0000106#else
107#ifndef GCC_PRINTFLIKE
108#define GCC_PRINTFLIKE(fmt,var) /* nothing */
109#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000110#ifndef GCC_NOTUSED
111#define GCC_NOTUSED
112#endif
Lev Walkin64399722004-08-11 07:17:22 +0000113#endif
114
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000115/* Figure out if thread safety is requested */
Lev Walkin27f53bc2007-06-29 12:10:50 +0000116#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000117#define ASN_THREAD_SAFE
118#endif /* Thread safety */
119
Lev Walkin64399722004-08-11 07:17:22 +0000120#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +0000121#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
122#endif /* offsetof */
123
Lev Walkinf15320b2004-06-03 03:38:44 +0000124#ifndef MIN /* Suitable for comparing primitive types (integers) */
125#if defined(__GNUC__)
126#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
127 ((_a)<(_b)?(_a):(_b)); })
128#else /* !__GNUC__ */
129#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
130#endif /* __GNUC__ */
131#endif /* MIN */
132
Lev Walkinc6cac8e2016-03-14 02:57:07 -0700133#endif /* ASN_SYSTEM_H */