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