]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
Android: hack to fix warnings in pthread.h when compiling in C++
[vlc] / include / vlc_fixups.h
1 /*****************************************************************************
2  * fixups.h: portability fixups included from config.h
3  *****************************************************************************
4  * Copyright © 1998-2008 the VideoLAN project
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 /**
22  * \file
23  * This file is a collection of portability fixes
24  */
25
26 #ifndef LIBVLC_FIXUPS_H
27 # define LIBVLC_FIXUPS_H 1
28
29 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R)
30 # include <time.h> /* time_t */
31 #endif
32
33 #ifndef HAVE_LLDIV
34 typedef struct
35 {
36     long long quot; /* Quotient. */
37     long long rem;  /* Remainder. */
38 } lldiv_t;
39 #endif
40
41 #if !defined(HAVE_GETENV) || \
42     !defined(HAVE_USELOCALE)
43 # include <stddef.h> /* NULL */
44 #endif
45
46 #if !defined (HAVE_REWIND) || \
47     !defined (HAVE_GETDELIM)
48 # include <stdio.h> /* FILE */
49 #endif
50
51 #if !defined (HAVE_STRLCPY) || \
52     !defined (HAVE_STRNDUP) || \
53     !defined (HAVE_STRNLEN) || \
54     !defined (HAVE_GETCWD)
55 # include <stddef.h> /* size_t */
56 #endif
57
58 #ifndef HAVE_VASPRINTF
59 # include <stdarg.h> /* va_list */
60 #endif
61
62 #if !defined (HAVE_GETDELIM) || \
63     !defined (HAVE_GETPID)   || \
64     !defined (HAVE_SWAB)
65 # include <sys/types.h> /* ssize_t, pid_t */
66 #endif
67
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72 #ifndef HAVE_STRDUP
73 char *strdup (const char *);
74 #endif
75
76 #ifndef HAVE_VASPRINTF
77 int vasprintf (char **, const char *, va_list);
78 #endif
79
80 #ifndef HAVE_ASPRINTF
81 int asprintf (char **, const char *, ...);
82 #endif
83
84 #ifndef HAVE_STRNLEN
85 size_t strnlen (const char *, size_t);
86 #endif
87
88 #ifndef HAVE_STRNDUP
89 char *strndup (const char *, size_t);
90 #endif
91
92 #ifndef HAVE_STRLCPY
93 size_t strlcpy (char *, const char *, size_t);
94 #endif
95
96 #ifndef HAVE_STRTOF
97 #ifndef __ANDROID__
98 float strtof (const char *, char **);
99 #endif
100 #endif
101
102 #ifndef HAVE_ATOF
103 #ifndef __ANDROID__
104 double atof (const char *);
105 #endif
106 #endif
107
108 #ifndef HAVE_STRTOLL
109 long long int strtoll (const char *, char **, int);
110 #endif
111
112 #ifndef HAVE_STRSEP
113 char *strsep (char **, const char *);
114 #endif
115
116 #ifndef HAVE_ATOLL
117 long long atoll (const char *);
118 #endif
119
120 #ifndef HAVE_LLDIV
121 lldiv_t lldiv (long long, long long);
122 #endif
123
124 #ifndef HAVE_STRCASECMP
125 int strcasecmp (const char *, const char *);
126 #endif
127
128 #ifndef HAVE_STRNCASECMP
129 int strncasecmp (const char *, const char *, size_t);
130 #endif
131
132 #ifndef HAVE_STRCASESTR
133 char *strcasestr (const char *, const char *);
134 #endif
135
136 #ifndef HAVE_GMTIME_R
137 struct tm *gmtime_r (const time_t *, struct tm *);
138 #endif
139
140 #ifndef HAVE_LOCALTIME_R
141 struct tm *localtime_r (const time_t *, struct tm *);
142 #endif
143
144 #ifndef HAVE_REWIND
145 void rewind (FILE *);
146 #endif
147
148 #ifndef HAVE_GETCWD
149 char *getcwd (char *buf, size_t size);
150 #endif
151
152 #ifndef HAVE_GETDELIM
153 ssize_t getdelim (char **, size_t *, int, FILE *);
154 ssize_t getline (char **, size_t *, FILE *);
155 #endif
156
157 #ifndef HAVE_GETPID
158 pid_t getpid (void);
159 #endif
160
161 #ifndef HAVE_STRTOK_R
162 char *strtok_r(char *, const char *, char **);
163 #endif
164
165 #ifdef __cplusplus
166 } /* extern "C" */
167 #endif
168
169 #ifndef HAVE_GETENV
170 static inline char *getenv (const char *name)
171 {
172     (void)name;
173     return NULL;
174 }
175 #endif
176
177 #ifndef HAVE_SETENV
178 int setenv (const char *, const char *, int);
179 int unsetenv (const char *);
180 #endif
181
182 /* Alignment of critical static data structures */
183 #ifdef ATTRIBUTE_ALIGNED_MAX
184 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
185 #else
186 #   define ATTR_ALIGN(align)
187 #endif
188
189 #ifndef HAVE_USELOCALE
190 #define LC_NUMERIC_MASK  0
191 #define LC_MESSAGES_MASK 0
192 typedef void *locale_t;
193 static inline locale_t uselocale(locale_t loc)
194 {
195     (void)loc;
196     return NULL;
197 }
198 static inline void freelocale(locale_t loc)
199 {
200     (void)loc;
201 }
202 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
203 {
204     (void)mask; (void)locale; (void)base;
205     return NULL;
206 }
207 #endif
208
209 /* libintl support */
210 #define _(str)            vlc_gettext (str)
211 #define N_(str)           gettext_noop (str)
212 #define gettext_noop(str) (str)
213
214 #ifndef HAVE_SWAB
215 void swab (const void *, void *, ssize_t);
216 #endif
217
218 /* Socket stuff */
219 #ifndef HAVE_INET_PTON
220 # define inet_pton vlc_inet_pton
221 #endif
222
223 #ifndef HAVE_INET_NTOP
224 # define inet_ntop vlc_inet_ntop
225 #endif
226
227 #ifndef HAVE_POLL
228 enum
229 {
230     POLLIN=1,
231     POLLOUT=2,
232     POLLPRI=4,
233     POLLERR=8,  // unsupported stub
234     POLLHUP=16, // unsupported stub
235     POLLNVAL=32 // unsupported stub
236 };
237
238 struct pollfd
239 {
240     int fd;
241     unsigned events;
242     unsigned revents;
243 };
244
245 # define poll(a, b, c) vlc_poll(a, b, c)
246 #elif defined (HAVE_MAEMO)
247 # include <poll.h>
248 # define poll(a, b, c) vlc_poll(a, b, c)
249 int vlc_poll (struct pollfd *, unsigned, int);
250 #endif
251
252 #ifndef HAVE_SEARCH_H
253 typedef struct entry {
254     char *key;
255     void *data;
256 } ENTRY;
257
258 typedef enum {
259     FIND, ENTER
260 } ACTION;
261
262 typedef enum {
263     preorder,
264     postorder,
265     endorder,
266     leaf
267 } VISIT;
268
269 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
270 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
271 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
272 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
273 void tdestroy( void *root, void (*free_node)(void *nodep) );
274 #else // HAVE_SEARCH_H
275 # ifndef HAVE_TDESTROY
276 #  define tdestroy vlc_tdestroy
277 # endif
278 #endif
279
280 /* Random numbers */
281 #ifndef HAVE_NRAND48
282 double erand48 (unsigned short subi[3]);
283 long jrand48 (unsigned short subi[3]);
284 long nrand48 (unsigned short subi[3]);
285 #endif
286
287 #ifdef __ANDROID__
288 # undef __linux__
289 # ifndef __cplusplus
290 #  define __cplusplus 0
291 # endif
292 # include <pthread.h>
293 # if __cplusplus == 0
294 #  undef __cplusplus
295 # endif
296 char *tempnam(const char *, const char *);
297 #endif // ANDROID
298
299 #endif /* !LIBVLC_FIXUPS_H */