asn1c/skeletons/asn_system.h

138 lines
3.4 KiB
C
Raw Permalink Normal View History

2004-06-03 03:38:44 +00:00
/*-
2007-06-29 11:38:57 +00:00
* Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
* All rights reserved.
2004-06-03 03:38:44 +00:00
* Redistribution and modifications are permitted subject to BSD license.
*/
/*
* Miscellaneous system-dependent types.
*/
2016-03-14 09:57:07 +00:00
#ifndef ASN_SYSTEM_H
#define ASN_SYSTEM_H
2004-06-03 03:38:44 +00:00
2004-09-07 10:47:39 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef _BSD_SOURCE
#define _BSD_SOURCE /* for snprintf() on some linux systems */
#endif
#include <stdio.h> /* For snprintf(3) */
2004-06-03 03:38:44 +00:00
#include <stdlib.h> /* For *alloc(3) */
#include <string.h> /* For memcpy(3) */
#include <sys/types.h> /* For size_t */
#include <limits.h> /* For LONG_MAX */
2004-06-03 03:38:44 +00:00
#include <stdarg.h> /* For va_start */
#include <stddef.h> /* for offsetof and ptrdiff_t */
2004-09-07 10:47:39 +00:00
2016-07-02 19:55:23 +00:00
#ifdef HAVE_ALLOCA_H
#include <alloca.h> /* For alloca(3) */
#endif
#ifdef _WIN32
2004-09-07 10:47:39 +00:00
2006-05-02 18:55:41 +00:00
#include <malloc.h>
2005-02-25 14:20:30 +00:00
#define snprintf _snprintf
#define vsnprintf _vsnprintf
2006-11-21 10:38:50 +00:00
/* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
2006-11-27 13:31:35 +00:00
#define sys_ntohl(l) ((((l) << 24) & 0xff000000) \
| (((l) << 8) & 0xff0000) \
| (((l) >> 8) & 0xff00) \
| ((l >> 24) & 0xff))
2006-11-21 10:38:50 +00:00
2005-05-27 20:56:08 +00:00
#ifdef _MSC_VER /* MSVS.Net */
2005-08-17 18:39:36 +00:00
#ifndef __cplusplus
#define inline __inline
#endif
2007-11-13 23:32:38 +00:00
#ifndef ASSUMESTDTYPES /* Standard types have been defined elsewhere */
2005-05-27 20:56:08 +00:00
#define ssize_t SSIZE_T
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
2007-11-13 23:32:38 +00:00
#endif /* ASSUMESTDTYPES */
2010-11-28 01:08:12 +00:00
#define WIN32_LEAN_AND_MEAN
2005-05-27 20:56:08 +00:00
#include <windows.h>
#include <float.h>
#define isnan _isnan
#define finite _finite
#define copysign _copysign
#define ilogb _logb
#else /* !_MSC_VER */
#include <stdint.h>
2005-05-27 20:56:08 +00:00
#endif /* _MSC_VER */
#else /* !_WIN32 */
2005-02-25 14:20:30 +00:00
2006-05-02 18:55:41 +00:00
#if defined(__vxworks)
#include <types/vxTypes.h>
#else /* !defined(__vxworks) */
2005-02-25 14:20:30 +00:00
#include <inttypes.h> /* C99 specifies this file */
2004-09-07 10:47:39 +00:00
/*
* 1. Earlier FreeBSD version didn't have <stdint.h>,
2004-09-07 10:47:39 +00:00
* but <inttypes.h> was present.
* 2. Sun Solaris requires <alloca.h> for alloca(3),
* but does not have <stdint.h>.
2004-09-07 10:47:39 +00:00
*/
2004-10-25 22:58:35 +00:00
#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
#if defined(sun)
#include <alloca.h> /* For alloca(3) */
2005-02-25 14:20:30 +00:00
#include <ieeefp.h> /* for finite(3) */
2006-03-16 22:29:55 +00:00
#elif defined(__hpux)
#ifdef __GNUC__
#include <alloca.h> /* For alloca(3) */
#else /* !__GNUC__ */
#define inline
#endif /* __GNUC__ */
#else
2004-09-07 07:26:32 +00:00
#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
2005-02-25 14:20:30 +00:00
#endif /* defined(sun) */
#endif
2004-08-11 07:17:22 +00:00
2006-11-21 10:38:50 +00:00
#include <netinet/in.h> /* for ntohl() */
#define sys_ntohl(foo) ntohl(foo)
2006-05-02 18:55:41 +00:00
#endif /* defined(__vxworks) */
#endif /* _WIN32 */
2004-08-11 07:17:22 +00:00
#if __GNUC__ >= 3
#ifndef GCC_PRINTFLIKE
#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
#endif
2006-10-16 12:01:36 +00:00
#ifndef GCC_NOTUSED
#define GCC_NOTUSED __attribute__((unused))
#endif
#else
#ifndef GCC_PRINTFLIKE
#define GCC_PRINTFLIKE(fmt,var) /* nothing */
#endif
2006-10-16 12:01:36 +00:00
#ifndef GCC_NOTUSED
#define GCC_NOTUSED
#endif
2004-08-11 07:17:22 +00:00
#endif
2004-06-03 03:38:44 +00:00
2007-06-29 11:38:57 +00:00
/* Figure out if thread safety is requested */
2007-06-29 12:10:50 +00:00
#if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
2007-06-29 11:38:57 +00:00
#define ASN_THREAD_SAFE
#endif /* Thread safety */
2004-08-11 07:17:22 +00:00
#ifndef offsetof /* If not defined by <stddef.h> */
2004-06-03 03:38:44 +00:00
#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
#endif /* offsetof */
#ifndef MIN /* Suitable for comparing primitive types (integers) */
#if defined(__GNUC__)
#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
((_a)<(_b)?(_a):(_b)); })
#else /* !__GNUC__ */
#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
#endif /* __GNUC__ */
#endif /* MIN */
2016-03-14 09:57:07 +00:00
#endif /* ASN_SYSTEM_H */