blob: fe7e5a8fe7ff6537a0943d8a1ef3cf9177649c72 [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
24#define snprintf _snprintf
25#define vsnprintf _vsnprintf
26#define alloca(size) _alloca(size)
27
Lev Walkin4cca5092005-05-27 20:56:08 +000028#ifdef _MSC_VER /* MSVS.Net */
29#define ssize_t SSIZE_T
30typedef char int8_t;
31typedef short int16_t;
32typedef int int32_t;
33typedef unsigned char uint8_t;
34typedef unsigned short uint16_t;
35typedef unsigned int uint32_t;
36#define WIN32_LEAN_AND_MEAN
37#include <windows.h>
38#endif /* _MSC_VER */
39
Lev Walkin4efbfb72005-02-25 14:20:30 +000040#else /* !WIN32 */
41
Lev Walkin0ede18c2004-09-07 10:47:39 +000042#include <inttypes.h> /* C99 specifies this file */
Lev Walkin0ede18c2004-09-07 10:47:39 +000043/*
Lev Walkina460ba32004-10-20 15:40:04 +000044 * 1. Earlier FreeBSD version didn't have <stdint.h>,
Lev Walkin0ede18c2004-09-07 10:47:39 +000045 * but <inttypes.h> was present.
Lev Walkina460ba32004-10-20 15:40:04 +000046 * 2. Sun Solaris requires <alloca.h> for alloca(3),
47 * but does not have <stdint.h>.
Lev Walkin0ede18c2004-09-07 10:47:39 +000048 */
Lev Walkineeab25b2004-10-25 22:58:35 +000049#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
Lev Walkina460ba32004-10-20 15:40:04 +000050#if defined(sun)
51#include <alloca.h> /* For alloca(3) */
Lev Walkin4efbfb72005-02-25 14:20:30 +000052#include <ieeefp.h> /* for finite(3) */
Lev Walkina460ba32004-10-20 15:40:04 +000053#else
Lev Walkin1ff369a2004-09-07 07:26:32 +000054#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
Lev Walkin4efbfb72005-02-25 14:20:30 +000055#endif /* defined(sun) */
Lev Walkina460ba32004-10-20 15:40:04 +000056#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000057
Lev Walkin1ff369a2004-09-07 07:26:32 +000058#endif /* WIN32 */
Lev Walkin64399722004-08-11 07:17:22 +000059
60#ifndef __GNUC__
61#define __attribute__(ignore)
62#endif
63
64#ifndef offsetof /* If not defined by <stddef.h> */
Lev Walkinf15320b2004-06-03 03:38:44 +000065#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
66#endif /* offsetof */
67
Lev Walkinf15320b2004-06-03 03:38:44 +000068#ifndef MIN /* Suitable for comparing primitive types (integers) */
69#if defined(__GNUC__)
70#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
71 ((_a)<(_b)?(_a):(_b)); })
72#else /* !__GNUC__ */
73#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
74#endif /* __GNUC__ */
75#endif /* MIN */
76
Lev Walkindc06f6b2004-10-20 15:50:55 +000077#endif /* _ASN_SYSTEM_H_ */