blob: d19837edf59e4222c64ab885e63a5f61e6657728 [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 Walkinbce0ce42016-07-02 23:51:32 -070016#ifndef _BSD_SOURCE
17#define _BSD_SOURCE /* for snprintf() on some linux systems */
18#endif
19
Lev Walkina460ba32004-10-20 15:40:04 +000020#include <stdio.h> /* For snprintf(3) */
Lev Walkinf15320b2004-06-03 03:38:44 +000021#include <stdlib.h> /* For *alloc(3) */
22#include <string.h> /* For memcpy(3) */
23#include <sys/types.h> /* For size_t */
Lev Walkin5c879db2007-11-06 06:23:31 +000024#include <limits.h> /* For LONG_MAX */
Lev Walkinf15320b2004-06-03 03:38:44 +000025#include <stdarg.h> /* For va_start */
Lev Walkinf15320b2004-06-03 03:38:44 +000026#include <stddef.h> /* for offsetof and ptrdiff_t */
Lev Walkin0ede18c2004-09-07 10:47:39 +000027
Lev Walkin619f0cd2016-07-02 19:55:23 +000028#ifdef HAVE_ALLOCA_H
29#include <alloca.h> /* For alloca(3) */
30#endif
31
Lev Walkin93659562010-11-20 09:47:13 -080032#ifdef _WIN32
Lev Walkin4efbfb72005-02-25 14:20:30 +000033
Lev Walkinf689f0b2006-05-02 18:55:41 +000034#include <malloc.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000035#define snprintf _snprintf
36#define vsnprintf _vsnprintf
Lev Walkin4efbfb72005-02-25 14:20:30 +000037
Lev Walkin217f2402006-11-21 10:38:50 +000038/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
Lev Walkin349e8472006-11-27 13:31:35 +000039#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
Ilya Basin762747c2012-12-01 14:38:00 +040040 | (((l) << 8) & 0xff0000) \
41 | (((l) >> 8) & 0xff00) \
42 | ((l >> 24) & 0xff))
Lev Walkin217f2402006-11-21 10:38:50 +000043
Lev Walkin4cca5092005-05-27 20:56:08 +000044#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000045#ifndef __cplusplus
46#define inline __inline
47#endif
Lev Walkin8e391912007-11-13 23:32:38 +000048#ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
Lev Walkin4cca5092005-05-27 20:56:08 +000049#define ssize_t SSIZE_T
50typedef char int8_t;
51typedef short int16_t;
52typedef int int32_t;
53typedef unsigned char uint8_t;
54typedef unsigned short uint16_t;
55typedef unsigned int uint32_t;
Lev Walkin8e391912007-11-13 23:32:38 +000056#endif /* ASSUMESTDTYPES */
Lev Walkin05c81b72010-11-27 17:08:12 -080057#define WIN32_LEAN_AND_MEAN
Lev Walkin4cca5092005-05-27 20:56:08 +000058#include <windows.h>
Lev Walkin2f505022005-07-01 08:28:18 +000059#include <float.h>
60#define isnan _isnan
61#define finite _finite
62#define copysign _copysign
63#define ilogb _logb
Lev Walkin7943c302007-11-13 05:09:35 +000064#else /* !_MSC_VER */
65#include <stdint.h>
Lev Walkin4cca5092005-05-27 20:56:08 +000066#endif /* _MSC_VER */
67
Lev Walkin93659562010-11-20 09:47:13 -080068#else /* !_WIN32 */
Lev Walkin4efbfb72005-02-25 14:20:30 +000069
Lev Walkinf689f0b2006-05-02 18:55:41 +000070#if defined(__vxworks)
71#include <types/vxTypes.h>
72#else /* !defined(__vxworks) */
73
Lev Walkin0ede18c2004-09-07 10:47:39 +000074#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000075/*
Lev Walkina460ba32004-10-20 15:40:04 +000076 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000077 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000078 * 2. Sun Solaris requires <alloca.h> for alloca(3),
79 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000080 */
Lev Walkineeab25b2004-10-25 22:58:35 +000081#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000082#if defined(sun)
83#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000084#include <ieeefp.h> /* for finite(3) */
Lev Walkinfa956652006-03-16 22:29:55 +000085#elif defined(__hpux)
86#ifdef __GNUC__
87#include <alloca.h> /* For alloca(3) */
88#else /* !__GNUC__ */
89#define inline
90#endif /* __GNUC__ */
Lev Walkina460ba32004-10-20 15:40:04 +000091#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000092#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000093#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000094#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000095
Lev Walkin217f2402006-11-21 10:38:50 +000096#include <netinet/in.h> /* for ntohl() */
97#define sys_ntohl(foo) ntohl(foo)
98
Lev Walkinf689f0b2006-05-02 18:55:41 +000099#endif /* defined(__vxworks) */
100
Lev Walkin93659562010-11-20 09:47:13 -0800101#endif /* _WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +0000102
Lev Walkin3f6afc12006-09-15 18:52:36 +0000103#if __GNUC__ >= 3
104#ifndef GCC_PRINTFLIKE
105#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
106#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000107#ifndef GCC_NOTUSED
108#define GCC_NOTUSED __attribute__((unused))
109#endif
Lev Walkin3f6afc12006-09-15 18:52:36 +0000110#else
111#ifndef GCC_PRINTFLIKE
112#define GCC_PRINTFLIKE(fmt,var) /* nothing */
113#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000114#ifndef GCC_NOTUSED
115#define GCC_NOTUSED
116#endif
Lev Walkin64399722004-08-11 07:17:22 +0000117#endif
118
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000119/* Figure out if thread safety is requested */
Lev Walkin27f53bc2007-06-29 12:10:50 +0000120#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
Lev Walkin3e86a4e2007-06-29 11:38:57 +0000121#define ASN_THREAD_SAFE
122#endif /* Thread safety */
123
Lev Walkin64399722004-08-11 07:17:22 +0000124#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +0000125#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
126#endif /* offsetof */
127
Lev Walkinf15320b2004-06-03 03:38:44 +0000128#ifndef MIN /* Suitable for comparing primitive types (integers) */
129#if defined(__GNUC__)
130#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
131 ((_a)<(_b)?(_a):(_b)); })
132#else /* !__GNUC__ */
133#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
134#endif /* __GNUC__ */
135#endif /* MIN */
136
Lev Walkinc6cac8e2016-03-14 02:57:07 -0700137#endif /* ASN_SYSTEM_H */