qml: restore the focus on the last album when navigating back to the album view
[vlc.git] / include / vlc_fixups.h
blob8fd01da0ce702c2c1635dc0c241a4ed8b206d530
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(__MINGW32__) || defined(__UCLIBC__) || defined(__native_client__))
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 #ifndef __cplusplus
49 # ifdef HAVE_THREADS_H
50 # include <threads.h>
51 # elif !defined(thread_local)
52 # ifdef HAVE_THREAD_LOCAL
53 # define thread_local _Thread_local
54 # elif defined(_MSC_VER)
55 # define thread_local __declspec(thread)
56 # endif
57 # endif
58 #endif
60 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R) \
61 || !defined (HAVE_TIMEGM)
62 # include <time.h> /* time_t */
63 #endif
65 #ifndef HAVE_GETTIMEOFDAY
66 #ifdef _WIN32
67 #include <winsock2.h>
68 #else
69 #include <sys/time.h>
70 #endif
71 #endif
73 #ifndef HAVE_LLDIV
74 typedef struct
76 long long quot; /* Quotient. */
77 long long rem; /* Remainder. */
78 } lldiv_t;
79 #endif
81 #if !defined(HAVE_GETENV) || \
82 !defined(HAVE_USELOCALE)
83 # include <stddef.h> /* NULL */
84 #endif
86 #if !defined (HAVE_REWIND) || \
87 !defined (HAVE_GETDELIM)
88 # include <stdio.h> /* FILE */
89 #endif
91 #if !defined (HAVE_ALIGNED_ALLOC) || \
92 !defined (HAVE_MEMRCHR) || \
93 !defined (HAVE_POSIX_MEMALIGN) || \
94 !defined (HAVE_QSORT_R) || \
95 !defined (HAVE_STRLCPY) || \
96 !defined (HAVE_STRNDUP) || \
97 !defined (HAVE_STRNLEN) || \
98 !defined (HAVE_STRNSTR)
99 # include <stddef.h> /* size_t */
100 #endif
102 #ifndef HAVE_VASPRINTF
103 # include <stdarg.h> /* va_list */
104 #endif
106 #if !defined (HAVE_GETDELIM) || \
107 !defined (HAVE_GETPID) || \
108 !defined (HAVE_SWAB)
109 # include <sys/types.h> /* ssize_t, pid_t */
110 #endif
112 #if !defined (HAVE_DIRFD) || \
113 !defined (HAVE_FDOPENDIR)
114 # include <dirent.h>
115 #endif
117 #ifdef __cplusplus
118 # define VLC_NOTHROW throw ()
119 extern "C" {
120 #else
121 # define VLC_NOTHROW
122 #endif
124 /* signal.h */
125 #if !defined(HAVE_SIGWAIT) && defined(__native_client__)
126 /* NaCl does not define sigwait in signal.h. We need to include it here to
127 * define sigwait, because sigset_t is allowed to be either an integral or a
128 * struct. */
129 #include <signal.h>
130 int sigwait(const sigset_t *set, int *sig);
131 #endif
133 /* stddef.h */
134 #if !defined (__cplusplus) && !defined (HAVE_MAX_ALIGN_T)
135 typedef struct {
136 long long ll;
137 long double ld;
138 } max_align_t;
139 #endif
141 /* stdio.h */
142 #ifndef HAVE_ASPRINTF
143 int asprintf (char **, const char *, ...);
144 #endif
146 #ifndef HAVE_FLOCKFILE
147 void flockfile (FILE *);
148 void funlockfile (FILE *);
149 int getc_unlocked (FILE *);
150 int getchar_unlocked (void);
151 int putc_unlocked (int, FILE *);
152 int putchar_unlocked (int);
153 #endif
155 #ifndef HAVE_GETDELIM
156 ssize_t getdelim (char **, size_t *, int, FILE *);
157 ssize_t getline (char **, size_t *, FILE *);
158 #endif
160 #ifndef HAVE_REWIND
161 void rewind (FILE *);
162 #endif
164 #ifndef HAVE_VASPRINTF
165 int vasprintf (char **, const char *, va_list);
166 #endif
168 /* string.h */
169 #ifndef HAVE_MEMRCHR
170 void *memrchr(const void *, int, size_t);
171 #endif
173 #ifndef HAVE_STRCASECMP
174 int strcasecmp (const char *, const char *);
175 #endif
177 #ifndef HAVE_STRCASESTR
178 char *strcasestr (const char *, const char *);
179 #endif
181 #ifndef HAVE_STRDUP
182 char *strdup (const char *);
183 #endif
185 #ifndef HAVE_STRVERSCMP
186 int strverscmp (const char *, const char *);
187 #endif
189 #ifndef HAVE_STRNLEN
190 size_t strnlen (const char *, size_t);
191 #endif
193 #ifndef HAVE_STRNSTR
194 char * strnstr (const char *, const char *, size_t);
195 #endif
197 #ifndef HAVE_STRNDUP
198 char *strndup (const char *, size_t);
199 #endif
201 #ifndef HAVE_STRLCPY
202 size_t strlcpy (char *, const char *, size_t);
203 #endif
205 #ifndef HAVE_STRSEP
206 char *strsep (char **, const char *);
207 #endif
209 #ifndef HAVE_STRTOK_R
210 char *strtok_r(char *, const char *, char **);
211 #endif
213 /* stdlib.h */
214 #ifndef HAVE_ATOF
215 #ifndef __ANDROID__
216 double atof (const char *);
217 #endif
218 #endif
220 #ifndef HAVE_ATOLL
221 long long atoll (const char *);
222 #endif
224 #ifndef HAVE_LLDIV
225 lldiv_t lldiv (long long, long long);
226 #endif
228 #ifndef HAVE_STRTOF
229 #ifndef __ANDROID__
230 float strtof (const char *, char **);
231 #endif
232 #endif
234 #ifndef HAVE_STRTOLL
235 long long int strtoll (const char *, char **, int);
236 #endif
238 /* time.h */
239 #ifndef HAVE_GMTIME_R
240 struct tm *gmtime_r (const time_t *, struct tm *);
241 #endif
243 #ifndef HAVE_LOCALTIME_R
244 struct tm *localtime_r (const time_t *, struct tm *);
245 #endif
247 #ifndef HAVE_TIMEGM
248 time_t timegm(struct tm *);
249 #endif
251 #ifndef HAVE_TIMESPEC_GET
252 #define TIME_UTC 1
253 struct timespec;
254 int timespec_get(struct timespec *, int);
255 #endif
257 /* sys/time.h */
258 #ifndef HAVE_GETTIMEOFDAY
259 struct timezone;
260 int gettimeofday(struct timeval *, struct timezone *);
261 #endif
263 /* unistd.h */
264 #ifndef HAVE_GETPID
265 pid_t getpid (void) VLC_NOTHROW;
266 #endif
268 #ifndef HAVE_FSYNC
269 int fsync (int fd);
270 #endif
272 #ifndef HAVE_PATHCONF
273 long pathconf (const char *path, int name);
274 #endif
276 /* dirent.h */
277 #ifndef HAVE_DIRFD
278 int (dirfd) (DIR *);
279 #endif
281 #ifndef HAVE_FDOPENDIR
282 DIR *fdopendir (int);
283 #endif
285 #ifdef __cplusplus
286 } /* extern "C" */
287 #endif
289 /* stdlib.h */
290 #ifndef HAVE_GETENV
291 static inline char *getenv (const char *name)
293 (void)name;
294 return NULL;
296 #endif
298 #ifndef HAVE_SETENV
299 int setenv (const char *, const char *, int);
300 int unsetenv (const char *);
301 #endif
303 #ifndef HAVE_POSIX_MEMALIGN
304 int posix_memalign(void **, size_t, size_t);
305 #endif
307 #ifndef HAVE_ALIGNED_ALLOC
308 void *aligned_alloc(size_t, size_t);
309 #endif
311 #if defined (_WIN32) && defined(__MINGW32__)
312 #define aligned_free(ptr) __mingw_aligned_free(ptr)
313 #elif defined (_WIN32) && defined(_MSC_VER)
314 #define aligned_free(ptr) _aligned_free(ptr)
315 #else
316 #define aligned_free(ptr) free(ptr)
317 #endif
319 #if defined(__native_client__) && defined(__cplusplus)
320 # define HAVE_USELOCALE
321 #endif
323 #if !defined(HAVE_NEWLOCALE) && defined(HAVE_CXX_LOCALE_T) && defined(__cplusplus)
324 # include <locale>
325 # define HAVE_NEWLOCALE
326 #endif
328 /* locale.h */
329 #ifndef HAVE_USELOCALE
330 # ifndef HAVE_NEWLOCALE
331 # define LC_ALL_MASK 0
332 # define LC_NUMERIC_MASK 0
333 # define LC_MESSAGES_MASK 0
334 # define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
335 typedef void *locale_t;
337 static inline void freelocale(locale_t loc)
339 (void)loc;
341 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
343 (void)mask; (void)locale; (void)base;
344 return NULL;
346 # else
347 # include <locale.h>
348 # endif
350 static inline locale_t uselocale(locale_t loc)
352 (void)loc;
353 return NULL;
355 #endif
357 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
358 # define STATIC_ASSERT_CONCAT_(a, b) a##b
359 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
360 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
361 # define static_assert _Static_assert
362 #endif
364 /* libintl support */
365 #define _(str) vlc_gettext (str)
366 #define N_(str) gettext_noop (str)
367 #define gettext_noop(str) (str)
369 #ifdef __cplusplus
370 extern "C" {
371 #endif
373 #ifndef HAVE_SWAB
374 void swab (const void *, void *, ssize_t);
375 #endif
377 /* Socket stuff */
378 #ifndef HAVE_INET_PTON
379 # ifndef _WIN32
380 # include <sys/socket.h>
381 #else
382 typedef int socklen_t;
383 # endif
384 int inet_pton(int, const char *, void *);
385 const char *inet_ntop(int, const void *, char *, socklen_t);
386 #endif
388 /* NaCl has a broken netinet/tcp.h, so TCP_NODELAY is not set */
389 #if defined(__native_client__) && !defined( HAVE_NETINET_TCP_H )
390 # define TCP_NODELAY 1
391 #endif
393 #ifndef HAVE_STRUCT_POLLFD
394 enum
396 POLLERR=0x1,
397 POLLHUP=0x2,
398 POLLNVAL=0x4,
399 POLLWRNORM=0x10,
400 POLLWRBAND=0x20,
401 POLLRDNORM=0x100,
402 POLLRDBAND=0x200,
403 POLLPRI=0x400,
405 #define POLLIN (POLLRDNORM|POLLRDBAND)
406 #define POLLOUT (POLLWRNORM|POLLWRBAND)
408 struct pollfd
410 int fd;
411 short events;
412 short revents;
414 #endif
415 #ifndef HAVE_POLL
416 struct pollfd;
417 int poll (struct pollfd *, unsigned, int);
418 #endif
420 #ifndef HAVE_IF_NAMEINDEX
421 #include <errno.h>
422 # ifndef HAVE_STRUCT_IF_NAMEINDEX
423 struct if_nameindex
425 unsigned if_index;
426 char *if_name;
428 # endif
429 # define if_nameindex() (errno = ENOBUFS, NULL)
430 # define if_freenameindex(list) (void)0
431 #endif
433 #ifndef HAVE_STRUCT_TIMESPEC
434 struct timespec {
435 time_t tv_sec; /* Seconds */
436 long tv_nsec; /* Nanoseconds */
438 #endif
440 #ifdef _WIN32
441 struct iovec
443 void *iov_base;
444 size_t iov_len;
446 #define IOV_MAX 255
447 struct msghdr
449 void *msg_name;
450 size_t msg_namelen;
451 struct iovec *msg_iov;
452 size_t msg_iovlen;
453 void *msg_control;
454 size_t msg_controllen;
455 int msg_flags;
457 #endif
459 #ifdef _NEWLIB_VERSION
460 #define IOV_MAX 255
461 #endif
463 #ifndef HAVE_RECVMSG
464 struct msghdr;
465 ssize_t recvmsg(int, struct msghdr *, int);
466 #endif
468 #ifndef HAVE_SENDMSG
469 struct msghdr;
470 ssize_t sendmsg(int, const struct msghdr *, int);
471 #endif
473 /* search.h */
474 #ifndef HAVE_SEARCH_H
475 typedef struct entry {
476 char *key;
477 void *data;
478 } ENTRY;
480 typedef enum {
481 FIND, ENTER
482 } ACTION;
484 typedef enum {
485 preorder,
486 postorder,
487 endorder,
488 leaf
489 } VISIT;
491 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
492 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
493 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
494 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
495 void *lfind( const void *key, const void *base, size_t *nmemb,
496 size_t size, int(*cmp)(const void *, const void *) );
497 #endif /* HAVE_SEARCH_H */
499 #ifdef _WIN64
500 # ifdef HAVE_SEARCH_H
501 # include <search.h>
502 # endif
503 /* the Win32 prototype of lfind() expects an unsigned* for 'nelp' */
504 # define lfind(a,b,c,d,e) \
505 lfind((a),(b), &(unsigned){ (*(c) > UINT_MAX) ? UINT_MAX : *(c) }, (d),(e))
506 #endif /* _WIN64 */
508 #ifndef HAVE_TDESTROY
509 void tdestroy( void *root, void (*free_node)(void *nodep) );
510 #endif
512 /* Random numbers */
513 #ifndef HAVE_NRAND48
514 double erand48 (unsigned short subi[3]);
515 long jrand48 (unsigned short subi[3]);
516 long nrand48 (unsigned short subi[3]);
517 #endif
519 #ifdef __OS2__
520 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
522 # define SHUT_RD 0
523 # define SHUT_WR 1
524 # define SHUT_RDWR 2
526 /* GAI error codes */
527 # ifndef EAI_BADFLAGS
528 # define EAI_BADFLAGS -1
529 # endif
530 # ifndef EAI_NONAME
531 # define EAI_NONAME -2
532 # endif
533 # ifndef EAI_AGAIN
534 # define EAI_AGAIN -3
535 # endif
536 # ifndef EAI_FAIL
537 # define EAI_FAIL -4
538 # endif
539 # ifndef EAI_NODATA
540 # define EAI_NODATA -5
541 # endif
542 # ifndef EAI_FAMILY
543 # define EAI_FAMILY -6
544 # endif
545 # ifndef EAI_SOCKTYPE
546 # define EAI_SOCKTYPE -7
547 # endif
548 # ifndef EAI_SERVICE
549 # define EAI_SERVICE -8
550 # endif
551 # ifndef EAI_ADDRFAMILY
552 # define EAI_ADDRFAMILY -9
553 # endif
554 # ifndef EAI_MEMORY
555 # define EAI_MEMORY -10
556 # endif
557 # ifndef EAI_OVERFLOW
558 # define EAI_OVERFLOW -11
559 # endif
560 # ifndef EAI_SYSTEM
561 # define EAI_SYSTEM -12
562 # endif
564 # ifndef NI_NUMERICHOST
565 # define NI_NUMERICHOST 0x01
566 # define NI_NUMERICSERV 0x02
567 # define NI_NOFQDN 0x04
568 # define NI_NAMEREQD 0x08
569 # define NI_DGRAM 0x10
570 # endif
572 # ifndef NI_MAXHOST
573 # define NI_MAXHOST 1025
574 # define NI_MAXSERV 32
575 # endif
577 # define AI_PASSIVE 1
578 # define AI_CANONNAME 2
579 # define AI_NUMERICHOST 4
581 struct addrinfo
583 int ai_flags;
584 int ai_family;
585 int ai_socktype;
586 int ai_protocol;
587 size_t ai_addrlen;
588 struct sockaddr *ai_addr;
589 char *ai_canonname;
590 struct addrinfo *ai_next;
593 const char *gai_strerror (int);
595 int getaddrinfo (const char *node, const char *service,
596 const struct addrinfo *hints, struct addrinfo **res);
597 void freeaddrinfo (struct addrinfo *res);
598 int getnameinfo (const struct sockaddr *sa, socklen_t salen,
599 char *host, int hostlen, char *serv, int servlen,
600 int flags);
602 /* OS/2 does not support IPv6, yet. But declare these only for compilation */
603 # include <stdint.h>
605 struct in6_addr
607 uint8_t s6_addr[16];
610 struct sockaddr_in6
612 uint8_t sin6_len;
613 uint8_t sin6_family;
614 uint16_t sin6_port;
615 uint32_t sin6_flowinfo;
616 struct in6_addr sin6_addr;
617 uint32_t sin6_scope_id;
620 # define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
622 static const struct in6_addr in6addr_any =
623 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
625 # include <errno.h>
626 # ifndef EPROTO
627 # define EPROTO (ELAST + 1)
628 # endif
630 # ifndef HAVE_IF_NAMETOINDEX
631 # define if_nametoindex(name) atoi(name)
632 # endif
633 #endif
635 /* math.h */
637 #ifndef HAVE_NANF
638 #define nanf(tagp) NAN
639 #endif
641 #ifndef HAVE_SINCOS
642 void sincos(double, double *, double *);
643 void sincosf(float, float *, float *);
644 #endif
646 #ifndef HAVE_REALPATH
647 char *realpath(const char * restrict pathname, char * restrict resolved_path);
648 #endif
650 #ifdef _WIN32
651 FILE *vlc_win32_tmpfile(void);
652 #endif
654 /* mingw-w64 has a broken IN6_IS_ADDR_MULTICAST macro */
655 #if defined(_WIN32) && defined(__MINGW64_VERSION_MAJOR)
656 # define IN6_IS_ADDR_MULTICAST IN6_IS_ADDR_MULTICAST
657 #endif
659 #ifdef __APPLE__
660 # define fdatasync fsync
661 #endif
663 #ifdef __cplusplus
664 } /* extern "C" */
665 #endif
667 #endif /* !LIBVLC_FIXUPS_H */