pls: handle FindPrefix() failure and simplify
[vlc.git] / include / vlc_fixups.h
bloba14764ff00b5ba0679ddd2ae6edfe2b6d965211c
1 /*****************************************************************************
2 * vlc_fixups.h: portability fixups included from config.h
3 *****************************************************************************
4 * Copyright © 1998-2008 the VideoLAN project
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.
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.
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 *****************************************************************************/
21 /**
22 * \file
23 * This file is a collection of portability fixes
26 #ifndef LIBVLC_FIXUPS_H
27 # define LIBVLC_FIXUPS_H 1
29 /* needed to detect uClibc */
30 #ifdef HAVE_FEATURES_H
31 #include <features.h>
32 #endif
34 /* C++11 says there's no need to define __STDC_*_MACROS when including
35 * inttypes.h and stdint.h. */
36 #if defined (__cplusplus) && (!defined(HAVE_CXX11) || defined(__MINGW32__) || defined(__UCLIBC__))
37 # ifndef __STDC_FORMAT_MACROS
38 # define __STDC_FORMAT_MACROS 1
39 # endif
40 # ifndef __STDC_CONSTANT_MACROS
41 # define __STDC_CONSTANT_MACROS 1
42 # endif
43 # ifndef __STDC_LIMIT_MACROS
44 # define __STDC_LIMIT_MACROS 1
45 # endif
46 #endif
48 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R) \
49 || !defined (HAVE_TIMEGM)
50 # include <time.h> /* time_t */
51 #endif
53 #ifndef HAVE_GETTIMEOFDAY
54 #ifdef _WIN32
55 #include <winsock2.h>
56 #else
57 #include <sys/time.h>
58 #endif
59 #endif
61 #ifndef HAVE_LLDIV
62 typedef struct
64 long long quot; /* Quotient. */
65 long long rem; /* Remainder. */
66 } lldiv_t;
67 #endif
69 #if !defined(HAVE_GETENV) || \
70 !defined(HAVE_USELOCALE)
71 # include <stddef.h> /* NULL */
72 #endif
74 #if !defined (HAVE_REWIND) || \
75 !defined (HAVE_GETDELIM)
76 # include <stdio.h> /* FILE */
77 #endif
79 #if !defined (HAVE_POSIX_MEMALIGN) || \
80 !defined (HAVE_MEMRCHR) || \
81 !defined (HAVE_STRLCPY) || \
82 !defined (HAVE_STRNDUP) || \
83 !defined (HAVE_STRNLEN) || \
84 !defined (HAVE_STRNSTR)
85 # include <stddef.h> /* size_t */
86 #endif
88 #ifndef HAVE_VASPRINTF
89 # include <stdarg.h> /* va_list */
90 #endif
92 #if !defined (HAVE_GETDELIM) || \
93 !defined (HAVE_GETPID) || \
94 !defined (HAVE_SWAB)
95 # include <sys/types.h> /* ssize_t, pid_t */
96 #endif
98 #if !defined (HAVE_DIRFD) || \
99 !defined (HAVE_FDOPENDIR)
100 # include <dirent.h>
101 #endif
103 #ifdef __cplusplus
104 # define VLC_NOTHROW throw ()
105 extern "C" {
106 #else
107 # define VLC_NOTHROW
108 #endif
110 /* stdio.h */
111 #ifndef HAVE_ASPRINTF
112 int asprintf (char **, const char *, ...);
113 #endif
115 #ifndef HAVE_FLOCKFILE
116 void flockfile (FILE *);
117 int ftrylockfile (FILE *);
118 void funlockfile (FILE *);
119 int getc_unlocked (FILE *);
120 int getchar_unlocked (void);
121 int putc_unlocked (int, FILE *);
122 int putchar_unlocked (int);
123 #endif
125 #ifndef HAVE_GETDELIM
126 ssize_t getdelim (char **, size_t *, int, FILE *);
127 ssize_t getline (char **, size_t *, FILE *);
128 #endif
130 #ifndef HAVE_REWIND
131 void rewind (FILE *);
132 #endif
134 #ifndef HAVE_VASPRINTF
135 int vasprintf (char **, const char *, va_list);
136 #endif
138 /* string.h */
139 #ifndef HAVE_FFSLL
140 int ffsll(unsigned long long);
141 #endif
143 #ifndef HAVE_MEMRCHR
144 void *memrchr(const void *, int, size_t);
145 #endif
147 #ifndef HAVE_STRCASECMP
148 int strcasecmp (const char *, const char *);
149 #endif
151 #ifndef HAVE_STRCASESTR
152 char *strcasestr (const char *, const char *);
153 #endif
155 #ifndef HAVE_STRDUP
156 char *strdup (const char *);
157 #endif
159 #ifndef HAVE_STRVERSCMP
160 int strverscmp (const char *, const char *);
161 #endif
163 #ifndef HAVE_STRNLEN
164 size_t strnlen (const char *, size_t);
165 #endif
167 #ifndef HAVE_STRNSTR
168 char * strnstr (const char *, const char *, size_t);
169 #endif
171 #ifndef HAVE_STRNDUP
172 char *strndup (const char *, size_t);
173 #endif
175 #ifndef HAVE_STRLCPY
176 size_t strlcpy (char *, const char *, size_t);
177 #endif
179 #ifndef HAVE_STRSEP
180 char *strsep (char **, const char *);
181 #endif
183 #ifndef HAVE_STRTOK_R
184 char *strtok_r(char *, const char *, char **);
185 #endif
187 /* stdlib.h */
188 #ifndef HAVE_ATOF
189 #ifndef __ANDROID__
190 double atof (const char *);
191 #endif
192 #endif
194 #ifndef HAVE_ATOLL
195 long long atoll (const char *);
196 #endif
198 #ifndef HAVE_LLDIV
199 lldiv_t lldiv (long long, long long);
200 #endif
202 #ifndef HAVE_STRTOF
203 #ifndef __ANDROID__
204 float strtof (const char *, char **);
205 #endif
206 #endif
208 #ifndef HAVE_STRTOLL
209 long long int strtoll (const char *, char **, int);
210 #endif
212 /* time.h */
213 #ifndef HAVE_GMTIME_R
214 struct tm *gmtime_r (const time_t *, struct tm *);
215 #endif
217 #ifndef HAVE_LOCALTIME_R
218 struct tm *localtime_r (const time_t *, struct tm *);
219 #endif
221 #ifndef HAVE_TIMEGM
222 time_t timegm(struct tm *);
223 #endif
225 #ifndef HAVE_TIMESPEC_GET
226 #define TIME_UTC 1
227 struct timespec;
228 int timespec_get(struct timespec *, int);
229 #endif
231 /* sys/time.h */
232 #ifndef HAVE_GETTIMEOFDAY
233 struct timezone;
234 int gettimeofday(struct timeval *, struct timezone *);
235 #endif
237 /* unistd.h */
238 #ifndef HAVE_GETPID
239 pid_t getpid (void) VLC_NOTHROW;
240 #endif
242 #ifndef HAVE_FSYNC
243 int fsync (int fd);
244 #endif
246 /* dirent.h */
247 #ifndef HAVE_DIRFD
248 int (dirfd) (DIR *);
249 #endif
251 #ifndef HAVE_FDOPENDIR
252 DIR *fdopendir (int);
253 #endif
255 #ifdef __cplusplus
256 } /* extern "C" */
257 #endif
259 /* stdlib.h */
260 #ifndef HAVE_GETENV
261 static inline char *getenv (const char *name)
263 (void)name;
264 return NULL;
266 #endif
268 #ifndef HAVE_SETENV
269 int setenv (const char *, const char *, int);
270 int unsetenv (const char *);
271 #endif
273 #ifndef HAVE_POSIX_MEMALIGN
274 int posix_memalign (void **, size_t, size_t);
275 #endif
277 /* locale.h */
278 #ifndef HAVE_USELOCALE
279 #define LC_ALL_MASK 0
280 #define LC_NUMERIC_MASK 0
281 #define LC_MESSAGES_MASK 0
282 #define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
283 typedef void *locale_t;
284 static inline locale_t uselocale(locale_t loc)
286 (void)loc;
287 return NULL;
289 static inline void freelocale(locale_t loc)
291 (void)loc;
293 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
295 (void)mask; (void)locale; (void)base;
296 return NULL;
298 #endif
300 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
301 # define STATIC_ASSERT_CONCAT_(a, b) a##b
302 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
303 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
304 # define static_assert _Static_assert
305 #endif
307 /* Alignment of critical static data structures */
308 #ifdef ATTRIBUTE_ALIGNED_MAX
309 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
310 #else
311 # define ATTR_ALIGN(align)
312 #endif
314 /* libintl support */
315 #define _(str) vlc_gettext (str)
316 #define N_(str) gettext_noop (str)
317 #define gettext_noop(str) (str)
319 #ifdef __cplusplus
320 extern "C" {
321 #endif
323 #ifndef HAVE_SWAB
324 void swab (const void *, void *, ssize_t);
325 #endif
327 /* Socket stuff */
328 #ifndef HAVE_INET_PTON
329 # ifndef _WIN32
330 # include <sys/socket.h>
331 #else
332 typedef int socklen_t;
333 # endif
334 int inet_pton(int, const char *, void *);
335 const char *inet_ntop(int, const void *, char *, socklen_t);
336 #endif
338 #ifndef HAVE_STRUCT_POLLFD
339 enum
341 POLLERR=0x1,
342 POLLHUP=0x2,
343 POLLNVAL=0x4,
344 POLLWRNORM=0x10,
345 POLLWRBAND=0x20,
346 POLLRDNORM=0x100,
347 POLLRDBAND=0x200,
348 POLLPRI=0x400,
350 #define POLLIN (POLLRDNORM|POLLRDBAND)
351 #define POLLOUT (POLLWRNORM|POLLWRBAND)
353 struct pollfd
355 int fd;
356 unsigned events;
357 unsigned revents;
359 #endif
360 #ifndef HAVE_POLL
361 struct pollfd;
362 int poll (struct pollfd *, unsigned, int);
363 #endif
365 #ifndef HAVE_IF_NAMEINDEX
366 #include <errno.h>
367 struct if_nameindex
369 unsigned if_index;
370 char *if_name;
372 # ifndef HAVE_IF_NAMETOINDEX
373 # define if_nametoindex(name) atoi(name)
374 # endif
375 # define if_nameindex() (errno = ENOBUFS, NULL)
376 # define if_freenameindex(list) (void)0
377 #endif
379 #ifndef HAVE_STRUCT_TIMESPEC
380 struct timespec {
381 time_t tv_sec; /* Seconds */
382 long tv_nsec; /* Nanoseconds */
384 #endif
386 #ifdef _WIN32
387 struct iovec
389 void *iov_base;
390 size_t iov_len;
392 #define IOV_MAX 255
393 struct msghdr
395 void *msg_name;
396 size_t msg_namelen;
397 struct iovec *msg_iov;
398 size_t msg_iovlen;
399 void *msg_control;
400 size_t msg_controllen;
401 int msg_flags;
403 #endif
405 #ifndef HAVE_RECVMSG
406 struct msghdr;
407 ssize_t recvmsg(int, struct msghdr *, int);
408 #endif
410 #ifndef HAVE_SENDMSG
411 struct msghdr;
412 ssize_t sendmsg(int, const struct msghdr *, int);
413 #endif
415 /* search.h */
416 #ifndef HAVE_SEARCH_H
417 typedef struct entry {
418 char *key;
419 void *data;
420 } ENTRY;
422 typedef enum {
423 FIND, ENTER
424 } ACTION;
426 typedef enum {
427 preorder,
428 postorder,
429 endorder,
430 leaf
431 } VISIT;
433 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
434 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
435 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
436 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
437 void tdestroy( void *root, void (*free_node)(void *nodep) );
438 #else // HAVE_SEARCH_H
439 # ifndef HAVE_TDESTROY
440 void vlc_tdestroy( void *, void (*)(void *) );
441 # define tdestroy vlc_tdestroy
442 # endif
443 #endif
445 /* Random numbers */
446 #ifndef HAVE_NRAND48
447 double erand48 (unsigned short subi[3]);
448 long jrand48 (unsigned short subi[3]);
449 long nrand48 (unsigned short subi[3]);
450 #endif
452 #ifdef __OS2__
453 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
455 struct addrinfo
457 int ai_flags;
458 int ai_family;
459 int ai_socktype;
460 int ai_protocol;
461 size_t ai_addrlen;
462 struct sockaddr *ai_addr;
463 char *ai_canonname;
464 struct addrinfo *ai_next;
467 void freeaddrinfo (struct addrinfo *res);
468 #endif
470 /* math.h */
472 #ifndef HAVE_NANF
473 #define nanf(tagp) NAN
474 #endif
476 #ifdef _WIN32
477 FILE *vlc_win32_tmpfile(void);
478 #endif
480 #ifdef __cplusplus
481 } /* extern "C" */
482 #endif
484 #endif /* !LIBVLC_FIXUPS_H */