move the declaration of struct ast_channel ast_frame and ast_module
[asterisk/asterisk.git] / include / asterisk / compat.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  * 
4  * Copyright (C) 1999-2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * This program is free software, distributed under the terms of
9  * the GNU General Public License
10  */
11
12 /*! \file
13  * \brief General Definitions for Asterisk top level program
14  * Included by asterisk.h to handle platform-specific issues
15  * especially those related to header files.
16  */
17
18 #include "asterisk/compiler.h"
19
20 #ifndef _COMPAT_H
21 #define _COMPAT_H
22
23 #ifndef __STDC_VERSION__
24 /* flex output wants to find this defined. */
25 #define __STDC_VERSION__ 0
26 #endif
27
28 #ifdef HAVE_INTTYPES_H
29 #include <inttypes.h>
30 #endif
31
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35
36 #ifdef HAVE_STDDEF_H
37 #include <stddef.h>
38 #endif
39
40 #ifdef HAVE_STDINT_H
41 #include <stdint.h>
42 #endif
43
44 #ifdef HAVE_SYS_TYPES_H
45 #include <sys/types.h>
46 #endif
47
48 #include <stdarg.h>
49
50 #ifdef HAVE_STDLIB_H
51 #include <stdlib.h>
52 #endif
53
54 #ifdef HAVE_ALLOCA_H
55 #include <alloca.h>    /* not necessarily present - could be in stdlib */
56 #elif defined(HAVE_ALLOCA) && defined(__MINGW32__)
57 #include <malloc.h>    /* see if it is here... */
58 #endif
59
60 #include <stdio.h>      /* this is always present */
61
62 #ifdef HAVE_STRING_H
63 #include <string.h>
64 #endif
65
66 #ifdef HAVE_SYS_POLL_H
67 #include <sys/poll.h>
68 #else
69 #include "asterisk/poll-compat.h"
70 #endif
71
72 #if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
73 int asprintf(char **str, const char *fmt, ...);
74 #endif
75
76 #ifndef HAVE_GETLOADAVG
77 int getloadavg(double *list, int nelem);
78 #endif
79
80 #ifndef HAVE_SETENV
81 int setenv(const char *name, const char *value, int overwrite);
82 #endif
83
84 #ifndef HAVE_STRCASESTR
85 char *strcasestr(const char *, const char *);
86 #endif
87
88 #if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
89 char *strndup(const char *, size_t);
90 #endif
91
92 #ifndef HAVE_STRNLEN
93 size_t strnlen(const char *, size_t);
94 #endif
95
96 #ifndef HAVE_STRSEP
97 char* strsep(char** str, const char* delims);
98 #endif
99
100 #ifndef HAVE_STRTOQ
101 uint64_t strtoq(const char *nptr, char **endptr, int base);
102 #endif
103
104 #ifndef HAVE_UNSETENV
105 int unsetenv(const char *name);
106 #endif
107
108 #if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
109 int vasprintf(char **strp, const char *fmt, va_list ap);
110 #endif
111
112 #ifndef HAVE_STRLCAT
113 size_t strlcat(char *dst, const char *src, size_t siz);
114 #endif
115
116 #ifndef HAVE_STRLCPY
117 size_t strlcpy(char *dst, const char *src, size_t siz);
118 #endif
119
120 #include <errno.h>
121
122 #ifdef SOLARIS
123 #define __BEGIN_DECLS
124 #define __END_DECLS
125
126 #ifndef __P
127 #define __P(p) p
128 #endif
129
130 #include <alloca.h>
131 #include <strings.h>
132 #include <string.h>
133 #include <pthread.h>
134 #include <sys/stat.h>
135 #include <signal.h>
136 #include <netinet/in.h>
137 #include <dat/dat_platform_specific.h>
138
139 #ifndef BYTE_ORDER
140 #define LITTLE_ENDIAN   1234
141 #define BIG_ENDIAN      4321
142
143 #ifdef __sparc__
144 #define BYTE_ORDER      BIG_ENDIAN
145 #else
146 #define BYTE_ORDER      LITTLE_ENDIAN
147 #endif
148 #endif
149
150 #ifndef __BYTE_ORDER
151 #define __LITTLE_ENDIAN LITTLE_ENDIAN
152 #define __BIG_ENDIAN BIG_ENDIAN
153 #define __BYTE_ORDER BYTE_ORDER
154 #endif
155
156 #ifndef __BIT_TYPES_DEFINED__
157 #define __BIT_TYPES_DEFINED__
158 typedef unsigned char   u_int8_t;
159 typedef unsigned short  u_int16_t;
160 typedef unsigned int    u_int32_t;
161 #endif
162
163 #endif /* SOLARIS */
164
165 #ifdef __CYGWIN__
166 #define _WIN32_WINNT 0x0500
167 #ifndef INET_ADDRSTRLEN
168 #define INET_ADDRSTRLEN  16
169 #endif
170 #ifndef INET6_ADDRSTRLEN
171 #define INET6_ADDRSTRLEN 46
172 #endif
173 #endif /* __CYGWIN__ */
174
175 #ifdef __CYGWIN__
176 typedef unsigned long long uint64_t;
177 #endif
178
179 /*! \brief
180  * Definition of various structures that many asterisk files need,
181  * but only because they need to know that the type exists.
182  *
183  * We can move them to a different global header if necessary.
184  */
185 struct ast_channel;
186 struct ast_frame;
187 struct ast_module;
188
189 #endif