]> git.stg.codes - stg.git/blob - libs/smux/include/stg/asn_system.h
Update SMUX library.
[stg.git] / libs / smux / include / stg / asn_system.h
1 /*-
2  * Copyright (c) 2003, 2004, 2007 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 /*
7  * Miscellaneous system-dependent types.
8  */
9 #ifndef ASN_SYSTEM_H
10 #define ASN_SYSTEM_H
11
12 #ifdef  HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15
16 #ifndef _BSD_SOURCE
17 #define _BSD_SOURCE /* for snprintf() on some linux systems  */
18 #endif
19
20 #include <stdio.h>      /* For snprintf(3) */
21 #include <stdlib.h>     /* For *alloc(3) */
22 #include <string.h>     /* For memcpy(3) */
23 #include <sys/types.h>  /* For size_t */
24 #include <limits.h>     /* For LONG_MAX */
25 #include <stdarg.h>     /* For va_start */
26 #include <stddef.h>     /* for offsetof and ptrdiff_t */
27
28 #ifdef  HAVE_ALLOCA_H
29 #include <alloca.h>     /* For alloca(3) */
30 #endif
31
32 #ifdef  _WIN32
33
34 #include <malloc.h>
35 #define  snprintf       _snprintf
36 #define  vsnprintf      _vsnprintf
37
38 /* To avoid linking with ws2_32.lib, here's the definition of ntohl() */
39 #define sys_ntohl(l)    ((((l) << 24)  & 0xff000000)    \
40                         | (((l) << 8) & 0xff0000)       \
41                         | (((l) >> 8)  & 0xff00)        \
42                         | ((l >> 24) & 0xff))
43
44 #ifdef _MSC_VER                 /* MSVS.Net */
45 #ifndef __cplusplus
46 #define inline __inline
47 #endif
48 #ifndef ASSUMESTDTYPES  /* Standard types have been defined elsewhere */
49 #define ssize_t         SSIZE_T
50 typedef char            int8_t;
51 typedef short           int16_t;
52 typedef int             int32_t;
53 typedef unsigned char   uint8_t;
54 typedef unsigned short  uint16_t;
55 typedef unsigned int    uint32_t;
56 #endif  /* ASSUMESTDTYPES */
57 #define WIN32_LEAN_AND_MEAN
58 #include <windows.h>
59 #include <float.h>
60 #define isnan _isnan
61 #define finite _finite
62 #define copysign _copysign
63 #define ilogb   _logb
64 #else   /* !_MSC_VER */
65 #include <stdint.h>
66 #endif  /* _MSC_VER */
67
68 #else   /* !_WIN32 */
69
70 #if defined(__vxworks)
71 #include <types/vxTypes.h>
72 #else   /* !defined(__vxworks) */
73
74 #include <inttypes.h>   /* C99 specifies this file */
75 /*
76  * 1. Earlier FreeBSD version didn't have <stdint.h>,
77  * but <inttypes.h> was present.
78  * 2. Sun Solaris requires <alloca.h> for alloca(3),
79  * but does not have <stdint.h>.
80  */
81 #if     (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
82 #if     defined(sun)
83 #include <alloca.h>     /* For alloca(3) */
84 #include <ieeefp.h>     /* for finite(3) */
85 #elif   defined(__hpux)
86 #ifdef  __GNUC__
87 #include <alloca.h>     /* For alloca(3) */
88 #else   /* !__GNUC__ */
89 #define inline
90 #endif  /* __GNUC__ */
91 #else
92 #include <stdint.h>     /* SUSv2+ and C99 specify this file, for uintXX_t */
93 #endif  /* defined(sun) */
94 #endif
95
96 #include <netinet/in.h> /* for ntohl() */
97 #define sys_ntohl(foo)  ntohl(foo)
98
99 #endif  /* defined(__vxworks) */
100
101 #endif  /* _WIN32 */
102
103 #if     __GNUC__ >= 3
104 #ifndef GCC_PRINTFLIKE
105 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
106 #endif
107 #ifndef GCC_NOTUSED
108 #define GCC_NOTUSED             __attribute__((unused))
109 #endif
110 #else
111 #ifndef GCC_PRINTFLIKE
112 #define GCC_PRINTFLIKE(fmt,var) /* nothing */
113 #endif
114 #ifndef GCC_NOTUSED
115 #define GCC_NOTUSED
116 #endif
117 #endif
118
119 /* Figure out if thread safety is requested */
120 #if !defined(ASN_THREAD_SAFE) && (defined(THREAD_SAFE) || defined(_REENTRANT))
121 #define ASN_THREAD_SAFE
122 #endif  /* Thread safety */
123
124 #ifndef offsetof        /* If not defined by <stddef.h> */
125 #define offsetof(s, m)  ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
126 #endif  /* offsetof */
127
128 #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
137 #endif  /* ASN_SYSTEM_H */