]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
Missing poll() declaration
[vlc] / include / vlc_fixups.h
1 /*****************************************************************************
2  * vlc_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 it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * 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     defined (__APPLE__)
49 # include <stdio.h> /* FILE */
50 #endif
51
52 #if !defined (HAVE_STRLCPY) || \
53     !defined (HAVE_STRNDUP) || \
54     !defined (HAVE_STRNLEN)
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) || defined (__APPLE__) || \
63     !defined (HAVE_GETPID)   || \
64     !defined (HAVE_SWAB)
65 # include <sys/types.h> /* ssize_t, pid_t */
66 #endif
67
68 #if !defined (HAVE_DIRFD) || \
69     !defined (HAVE_FDOPENDIR)
70 # include <dirent.h>
71 #endif
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
77 /* stdio.h */
78 #ifndef HAVE_ASPRINTF
79 int asprintf (char **, const char *, ...);
80 #endif
81
82 #ifndef HAVE_FLOCKFILE
83 void flockfile (FILE *);
84 int ftrylockfile (FILE *);
85 void funlockfile (FILE *);
86 int getc_unlocked (FILE *);
87 int getchar_unlocked (void);
88 int putc_unlocked (int, FILE *);
89 int putchar_unlocked (int);
90 #endif
91
92 /* we always need our implementation on Darwin, since native support for getline
93  * was added lately to Darwin 11 (OS X Lion) only.
94  * However, we want binaries created on this OS to be executable on previous
95  * releases. */
96 #if !defined HAVE_GETDELIM
97 ssize_t getdelim (char **, size_t *, int, FILE *);
98 ssize_t getline (char **, size_t *, FILE *);
99 #endif
100
101 #ifndef HAVE_REWIND
102 void rewind (FILE *);
103 #endif
104
105 #ifndef HAVE_VASPRINTF
106 int vasprintf (char **, const char *, va_list);
107 #endif
108
109 /* string.h */
110 #ifndef HAVE_STRCASECMP
111 int strcasecmp (const char *, const char *);
112 #endif
113
114 #ifndef HAVE_STRCASESTR
115 char *strcasestr (const char *, const char *);
116 #endif
117
118 #ifndef HAVE_STRDUP
119 char *strdup (const char *);
120 #endif
121
122 #ifndef HAVE_STRNCASECMP
123 int strncasecmp (const char *, const char *, size_t);
124 #endif
125
126 #ifndef HAVE_STRNLEN
127 size_t strnlen (const char *, size_t);
128 #endif
129
130 #ifndef HAVE_STRNDUP
131 char *strndup (const char *, size_t);
132 #endif
133
134 #ifndef HAVE_STRLCPY
135 size_t strlcpy (char *, const char *, size_t);
136 #endif
137
138 #ifndef HAVE_STRSEP
139 char *strsep (char **, const char *);
140 #endif
141
142 #ifndef HAVE_STRTOK_R
143 char *strtok_r(char *, const char *, char **);
144 #endif
145
146 /* stdlib.h */
147 #ifndef HAVE_ATOF
148 #ifndef __ANDROID__
149 double atof (const char *);
150 #endif
151 #endif
152
153 #ifndef HAVE_ATOLL
154 long long atoll (const char *);
155 #endif
156
157 #ifndef HAVE_LLDIV
158 lldiv_t lldiv (long long, long long);
159 #endif
160
161 #ifndef HAVE_STRTOF
162 #ifndef __ANDROID__
163 float strtof (const char *, char **);
164 #endif
165 #endif
166
167 #ifndef HAVE_STRTOLL
168 long long int strtoll (const char *, char **, int);
169 #endif
170
171 /* time.h */
172 #ifndef HAVE_GMTIME_R
173 struct tm *gmtime_r (const time_t *, struct tm *);
174 #endif
175
176 #ifndef HAVE_LOCALTIME_R
177 struct tm *localtime_r (const time_t *, struct tm *);
178 #endif
179
180 /* unistd.h */
181 #ifndef HAVE_GETPID
182 pid_t getpid (void);
183 #endif
184
185 #ifndef HAVE_FSYNC
186 int fsync (int fd);
187 #endif
188
189 /* dirent.h */
190 #ifndef HAVE_DIRFD
191 int (dirfd) (DIR *);
192 #endif
193
194 #ifndef HAVE_FDOPENDIR
195 DIR *fdopendir (int);
196 #endif
197
198 #ifdef __cplusplus
199 } /* extern "C" */
200 #endif
201
202 /* stdlib.h */
203 #ifndef HAVE_GETENV
204 static inline char *getenv (const char *name)
205 {
206     (void)name;
207     return NULL;
208 }
209 #endif
210
211 #ifndef HAVE_SETENV
212 int setenv (const char *, const char *, int);
213 int unsetenv (const char *);
214 #endif
215
216 /* locale.h */
217 #ifndef HAVE_USELOCALE
218 #define LC_NUMERIC_MASK  0
219 #define LC_MESSAGES_MASK 0
220 typedef void *locale_t;
221 static inline locale_t uselocale(locale_t loc)
222 {
223     (void)loc;
224     return NULL;
225 }
226 static inline void freelocale(locale_t loc)
227 {
228     (void)loc;
229 }
230 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
231 {
232     (void)mask; (void)locale; (void)base;
233     return NULL;
234 }
235 #endif
236
237 /* Alignment of critical static data structures */
238 #ifdef ATTRIBUTE_ALIGNED_MAX
239 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
240 #else
241 #   define ATTR_ALIGN(align)
242 #endif
243
244 /* libintl support */
245 #define _(str)            vlc_gettext (str)
246 #define N_(str)           gettext_noop (str)
247 #define gettext_noop(str) (str)
248
249 #ifndef HAVE_SWAB
250 void swab (const void *, void *, ssize_t);
251 #endif
252
253 /* Socket stuff */
254 #ifndef HAVE_INET_PTON
255 int inet_pton(int, const char *, void *);
256 const char *inet_ntop(int, const void *, char *, int);
257 #endif
258
259 #ifndef HAVE_STRUCT_POLLFD
260 enum
261 {
262     POLLIN=1,
263     POLLOUT=2,
264     POLLPRI=4,
265     POLLERR=8,  // unsupported stub
266     POLLHUP=16, // unsupported stub
267     POLLNVAL=32 // unsupported stub
268 };
269
270 struct pollfd
271 {
272     int fd;
273     unsigned events;
274     unsigned revents;
275 };
276 #endif
277 #ifndef HAVE_POLL
278 struct pollfd;
279 int poll (struct pollfd *, unsigned, int);
280 #endif
281
282 #ifndef HAVE_IF_NAMEINDEX
283 #include <errno.h>
284 struct if_nameindex
285 {
286     unsigned if_index;
287     char    *if_name;
288 };
289 # ifndef HAVE_IF_NAMETOINDEX
290 #  define if_nametoindex(name)   atoi(name)
291 # endif
292 # define if_nameindex()         (errno = ENOBUFS, NULL)
293 # define if_freenameindex(list) (void)0
294 #endif
295
296 /* search.h */
297 #ifndef HAVE_SEARCH_H
298 typedef struct entry {
299     char *key;
300     void *data;
301 } ENTRY;
302
303 typedef enum {
304     FIND, ENTER
305 } ACTION;
306
307 typedef enum {
308     preorder,
309     postorder,
310     endorder,
311     leaf
312 } VISIT;
313
314 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
315 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
316 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
317 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
318 void tdestroy( void *root, void (*free_node)(void *nodep) );
319 #else // HAVE_SEARCH_H
320 # ifndef HAVE_TDESTROY
321 #  define tdestroy vlc_tdestroy
322 # endif
323 #endif
324
325 /* Random numbers */
326 #ifndef HAVE_NRAND48
327 double erand48 (unsigned short subi[3]);
328 long jrand48 (unsigned short subi[3]);
329 long nrand48 (unsigned short subi[3]);
330 #endif
331
332 #ifdef __ANDROID__
333 # undef __linux__
334 # ifndef __cplusplus
335 #  define __cplusplus 0
336 # endif
337 # include <pthread.h>
338 # if __cplusplus == 0
339 #  undef __cplusplus
340 # endif
341 char *tempnam(const char *, const char *);
342 #endif // ANDROID
343
344 #ifdef __OS2__
345 # undef HAVE_FORK   /* Implementation of fork() is imperfect on OS/2 */
346 #endif
347
348 #endif /* !LIBVLC_FIXUPS_H */