blob: f920efc990a8a499f1a17689695dc2a686d87aca [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5/*
6 * Miscellaneous system-dependent types.
7 */
Lev Walkindc06f6b2004-10-20 15:50:55 +00008#ifndef _ASN_SYSTEM_H_
9#define _ASN_SYSTEM_H_
Lev Walkinf15320b2004-06-03 03:38:44 +000010
Lev Walkin0ede18c2004-09-07 10:47:39 +000011#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
Lev Walkina460ba32004-10-20 15:40:04 +000015#include <stdio.h> /* For snprintf(3) */
Lev Walkinf15320b2004-06-03 03:38:44 +000016#include <stdlib.h> /* For *alloc(3) */
17#include <string.h> /* For memcpy(3) */
18#include <sys/types.h> /* For size_t */
19#include <stdarg.h> /* For va_start */
Lev Walkinf15320b2004-06-03 03:38:44 +000020#include <stddef.h> /* for offsetof and ptrdiff_t */
Lev Walkin0ede18c2004-09-07 10:47:39 +000021
Lev Walkin4efbfb72005-02-25 14:20:30 +000022#ifdef WIN32
23
Lev Walkinf689f0b2006-05-02 18:55:41 +000024#include <malloc.h>
25#include <stdint.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000026#define snprintf _snprintf
27#define vsnprintf _vsnprintf
Lev Walkin4efbfb72005-02-25 14:20:30 +000028
Lev Walkin217f2402006-11-21 10:38:50 +000029/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
30#define sys_ntohl(l) ((((l) << 24) & 0xff000000)
31 | (((l) << 16) & 0xff0000)
32 | (((l) << 8) & 0xff00)
33 | ((l) & 0xff))
34
Lev Walkin4cca5092005-05-27 20:56:08 +000035#ifdef _MSC_VER /* MSVS.Net */
Lev Walkine44ea0b2005-08-17 18:39:36 +000036#ifndef __cplusplus
37#define inline __inline
38#endif
Lev Walkin4cca5092005-05-27 20:56:08 +000039#define ssize_t SSIZE_T
40typedef char int8_t;
41typedef short int16_t;
42typedef int int32_t;
43typedef unsigned char uint8_t;
44typedef unsigned short uint16_t;
45typedef unsigned int uint32_t;
46#define WIN32_LEAN_AND_MEAN
47#include <windows.h>
Lev Walkin2f505022005-07-01 08:28:18 +000048#include <float.h>
49#define isnan _isnan
50#define finite _finite
51#define copysign _copysign
52#define ilogb _logb
Lev Walkin4cca5092005-05-27 20:56:08 +000053#endif /* _MSC_VER */
54
Lev Walkin4efbfb72005-02-25 14:20:30 +000055#else /* !WIN32 */
56
Lev Walkinf689f0b2006-05-02 18:55:41 +000057#if defined(__vxworks)
58#include <types/vxTypes.h>
59#else /* !defined(__vxworks) */
60
Lev Walkin0ede18c2004-09-07 10:47:39 +000061#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000062/*
Lev Walkina460ba32004-10-20 15:40:04 +000063 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000064 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000065 * 2. Sun Solaris requires <alloca.h> for alloca(3),
66 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000067 */
Lev Walkineeab25b2004-10-25 22:58:35 +000068#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000069#if defined(sun)
70#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000071#include <ieeefp.h> /* for finite(3) */
Lev Walkinfa956652006-03-16 22:29:55 +000072#elif defined(__hpux)
73#ifdef __GNUC__
74#include <alloca.h> /* For alloca(3) */
75#else /* !__GNUC__ */
76#define inline
77#endif /* __GNUC__ */
Lev Walkina460ba32004-10-20 15:40:04 +000078#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000079#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000080#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000081#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000082
Lev Walkin217f2402006-11-21 10:38:50 +000083#include <netinet/in.h> /* for ntohl() */
84#define sys_ntohl(foo) ntohl(foo)
85
Lev Walkinf689f0b2006-05-02 18:55:41 +000086#endif /* defined(__vxworks) */
87
Lev Walkin1ff369a2004-09-07 07:26:32 +000088#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000089
Lev Walkin3f6afc12006-09-15 18:52:36 +000090#if __GNUC__ >= 3
91#ifndef GCC_PRINTFLIKE
92#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
93#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +000094#ifndef GCC_NOTUSED
95#define GCC_NOTUSED __attribute__((unused))
96#endif
Lev Walkin3f6afc12006-09-15 18:52:36 +000097#else
98#ifndef GCC_PRINTFLIKE
99#define GCC_PRINTFLIKE(fmt,var) /* nothing */
100#endif
Lev Walkin50b0f6c2006-10-16 12:01:36 +0000101#ifndef GCC_NOTUSED
102#define GCC_NOTUSED
103#endif
Lev Walkin64399722004-08-11 07:17:22 +0000104#endif
105
106#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +0000107#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
108#endif /* offsetof */
109
Lev Walkinf15320b2004-06-03 03:38:44 +0000110#ifndef MIN /* Suitable for comparing primitive types (integers) */
111#if defined(__GNUC__)
112#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
113 ((_a)<(_b)?(_a):(_b)); })
114#else /* !__GNUC__ */
115#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
116#endif /* __GNUC__ */
117#endif /* MIN */
118
Lev Walkindc06f6b2004-10-20 15:50:55 +0000119#endif /* _ASN_SYSTEM_H_ */