Wed Jan 8 2020 09:49:46

Asterisk developer's documentation


compat.h
Go to the documentation of this file.
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_LIMITS_H
33 #include <limits.h>
34 #endif
35 
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39 
40 #ifdef HAVE_STDDEF_H
41 #include <stddef.h>
42 #endif
43 
44 #ifdef HAVE_STDINT_H
45 #include <stdint.h>
46 #endif
47 
48 #ifdef HAVE_SYS_TYPES_H
49 #include <sys/types.h>
50 #endif
51 
52 #include <stdarg.h>
53 
54 #ifdef HAVE_STDLIB_H
55 #include <stdlib.h>
56 #endif
57 
58 #ifdef HAVE_ALLOCA_H
59 #include <alloca.h> /* not necessarily present - could be in stdlib */
60 #elif defined(HAVE_ALLOCA) && defined(__MINGW32__)
61 #include <malloc.h> /* see if it is here... */
62 #endif
63 
64 #include <stdio.h> /* this is always present */
65 
66 #ifdef HAVE_STRING_H
67 #include <string.h>
68 #endif
69 
70 #ifndef AST_POLL_COMPAT
71 #include <sys/poll.h>
72 #else
73 #include "asterisk/poll-compat.h"
74 #endif
75 
76 #ifndef HAVE_LLONG_MAX
77 #define LLONG_MAX 9223372036854775807LL
78 #endif
79 
80 #ifndef HAVE_CLOSEFROM
81 void closefrom(int lowfd);
82 #endif
83 
84 #if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC)
85 int __attribute__((format(printf, 2, 3))) asprintf(char **str, const char *fmt, ...);
86 #endif
87 
88 #ifndef HAVE_FFSLL
89 int ffsll(long long n);
90 #endif
91 
92 #ifndef HAVE_GETLOADAVG
93 int getloadavg(double *list, int nelem);
94 #endif
95 
96 #ifndef HAVE_HTONLL
97 uint64_t htonll(uint64_t host64);
98 #endif
99 
100 #ifndef HAVE_MKDTEMP
101 char *mkdtemp(char *template_s);
102 #endif
103 
104 #ifndef HAVE_NTOHLL
105 uint64_t ntohll(uint64_t net64);
106 #endif
107 
108 #ifndef HAVE_SETENV
109 int setenv(const char *name, const char *value, int overwrite);
110 #endif
111 
112 #ifndef HAVE_STRCASESTR
113 char *strcasestr(const char *, const char *);
114 #endif
115 
116 #if !defined(HAVE_STRNDUP) && !defined(__AST_DEBUG_MALLOC)
117 char *strndup(const char *, size_t);
118 #endif
119 
120 #ifndef HAVE_STRNLEN
121 size_t strnlen(const char *, size_t);
122 #endif
123 
124 #ifndef HAVE_STRSEP
125 char* strsep(char** str, const char* delims);
126 #endif
127 
128 #ifndef HAVE_STRTOQ
129 uint64_t strtoq(const char *nptr, char **endptr, int base);
130 #endif
131 
132 #ifndef HAVE_UNSETENV
133 int unsetenv(const char *name);
134 #endif
135 
136 #if !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC)
137 int __attribute__((format(printf, 2, 0))) vasprintf(char **strp, const char *fmt, va_list ap);
138 #endif
139 
140 #ifndef HAVE_TIMERSUB
141 void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff);
142 #endif
143 
144 #define strlcat __use__ast_str__functions_not__strlcat__
145 #define strlcpy __use__ast_copy_string__not__strlcpy__
146 
147 #include <errno.h>
148 
149 #ifdef SOLARIS
150 #define __BEGIN_DECLS
151 #define __END_DECLS
152 
153 #ifndef __P
154 #define __P(p) p
155 #endif
156 
157 #include <alloca.h>
158 #include <strings.h>
159 #include <string.h>
160 #include <pthread.h>
161 #include <sys/stat.h>
162 #include <signal.h>
163 #include <netinet/in.h>
164 #include <sys/loadavg.h>
165 #include <dat/dat_platform_specific.h>
166 
167 #ifndef BYTE_ORDER
168 #define LITTLE_ENDIAN 1234
169 #define BIG_ENDIAN 4321
170 
171 #ifdef __sparc__
172 #define BYTE_ORDER BIG_ENDIAN
173 #else
174 #define BYTE_ORDER LITTLE_ENDIAN
175 #endif
176 #endif
177 
178 #ifndef __BYTE_ORDER
179 #define __LITTLE_ENDIAN LITTLE_ENDIAN
180 #define __BIG_ENDIAN BIG_ENDIAN
181 #define __BYTE_ORDER BYTE_ORDER
182 #endif
183 
184 #ifndef __BIT_TYPES_DEFINED__
185 #define __BIT_TYPES_DEFINED__
186 typedef unsigned char u_int8_t;
187 typedef unsigned short u_int16_t;
188 typedef unsigned int u_int32_t;
189 typedef unsigned int uint;
190 #endif
191 
192 #endif /* SOLARIS */
193 
194 #ifdef __CYGWIN__
195 #define _WIN32_WINNT 0x0500
196 #ifndef INET_ADDRSTRLEN
197 #define INET_ADDRSTRLEN 16
198 #endif
199 #ifndef INET6_ADDRSTRLEN
200 #define INET6_ADDRSTRLEN 46
201 #endif
202 #endif /* __CYGWIN__ */
203 
204 #ifdef __CYGWIN__
205 typedef unsigned long long uint64_t;
206 #endif
207 
208 /* glob compat stuff */
209 #if defined(__Darwin__) || defined(__CYGWIN__)
210 #define GLOB_ABORTED GLOB_ABEND
211 #endif
212 #include <glob.h>
213 #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE)
214 #define MY_GLOB_FLAGS GLOB_NOCHECK
215 #else
216 #define MY_GLOB_FLAGS (GLOB_NOMAGIC | GLOB_BRACE)
217 #endif
218 
219 #ifndef HAVE_ROUNDF
220 #ifdef HAVE_ROUND
221 #define roundf(x) ((float)round(x))
222 #else
223 float roundf(float x);
224 #endif
225 #endif
226 
227 #endif
int vasprintf(char **strp, const char *fmt, va_list ap)
char * strsep(char **str, const char *delims)
String manipulation functions.
uint64_t ntohll(uint64_t net64)
Definition: strcompat.c:361
uint64_t strtoq(const char *nptr, char **endptr, int base)
uint64_t htonll(uint64_t host64)
Definition: strcompat.c:387
float roundf(float x)
const char * str
Definition: app_jack.c:144
int value
Definition: syslog.c:39
void closefrom(int lowfd)
Definition: strcompat.c:426
Compiler-specific macros and other items.
int ffsll(long long n)
int asprintf(char **str, const char *fmt,...)
char * mkdtemp(char *template_s)
void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
int setenv(const char *name, const char *value, int overwrite)
static const char name[]
size_t strnlen(const char *, size_t)
char * strcasestr(const char *, const char *)
static snd_pcm_format_t format
Definition: chan_alsa.c:93
struct ast_translator::@212 list
int getloadavg(double *list, int nelem)
int unsetenv(const char *name)
char * strndup(const char *, size_t)