demux: ogg: only invalid pts on no granule interpolation
[vlc.git] / include / vlc_fixups.h
blob2164f690b1466e39b34cf210c44751240bd0519b
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_QSORT_R) || \
94 !defined (HAVE_STRLCPY) || \
95 !defined (HAVE_STRNDUP) || \
96 !defined (HAVE_STRNLEN) || \
97 !defined (HAVE_STRNSTR)
98 # include <stddef.h> /* size_t */
99 #endif
101 #ifndef HAVE_VASPRINTF
102 # include <stdarg.h> /* va_list */
103 #endif
105 #if !defined (HAVE_GETDELIM) || \
106 !defined (HAVE_GETPID) || \
107 !defined (HAVE_SWAB)
108 # include <sys/types.h> /* ssize_t, pid_t */
109 #endif
111 #if !defined (HAVE_DIRFD) || \
112 !defined (HAVE_FDOPENDIR)
113 # include <dirent.h>
114 #endif
116 #ifdef __cplusplus
117 # define VLC_NOTHROW throw ()
118 extern "C" {
119 #else
120 # define VLC_NOTHROW
121 #endif
123 /* signal.h */
124 #if !defined(HAVE_SIGWAIT) && defined(__native_client__)
125 /* NaCl does not define sigwait in signal.h. We need to include it here to
126 * define sigwait, because sigset_t is allowed to be either an integral or a
127 * struct. */
128 #include <signal.h>
129 int sigwait(const sigset_t *set, int *sig);
130 #endif
132 /* stddef.h */
133 #if !defined (__cplusplus) && !defined (HAVE_MAX_ALIGN_T)
134 typedef struct {
135 long long ll;
136 long double ld;
137 } max_align_t;
138 #endif
140 /* stdio.h */
141 #ifndef HAVE_ASPRINTF
142 int asprintf (char **, const char *, ...);
143 #endif
145 #ifndef HAVE_FLOCKFILE
146 void flockfile (FILE *);
147 void funlockfile (FILE *);
148 int getc_unlocked (FILE *);
149 int getchar_unlocked (void);
150 int putc_unlocked (int, FILE *);
151 int putchar_unlocked (int);
152 #endif
154 #ifndef HAVE_GETDELIM
155 ssize_t getdelim (char **, size_t *, int, FILE *);
156 ssize_t getline (char **, size_t *, FILE *);
157 #endif
159 #ifndef HAVE_REWIND
160 void rewind (FILE *);
161 #endif
163 #ifndef HAVE_VASPRINTF
164 int vasprintf (char **, const char *, va_list);
165 #endif
167 /* string.h */
168 #ifndef HAVE_MEMRCHR
169 void *memrchr(const void *, int, size_t);
170 #endif
172 #ifndef HAVE_STRCASECMP
173 int strcasecmp (const char *, const char *);
174 #endif
176 #ifndef HAVE_STRCASESTR
177 char *strcasestr (const char *, const char *);
178 #endif
180 #ifndef HAVE_STRDUP
181 char *strdup (const char *);
182 #endif
184 #ifndef HAVE_STRVERSCMP
185 int strverscmp (const char *, const char *);
186 #endif
188 #ifndef HAVE_STRNLEN
189 size_t strnlen (const char *, size_t);
190 #endif
192 #ifndef HAVE_STRNSTR
193 char * strnstr (const char *, const char *, size_t);
194 #endif
196 #ifndef HAVE_STRNDUP
197 char *strndup (const char *, size_t);
198 #endif
200 #ifndef HAVE_STRLCPY
201 size_t strlcpy (char *, const char *, size_t);
202 #endif
204 #ifndef HAVE_STRSEP
205 char *strsep (char **, const char *);
206 #endif
208 #ifndef HAVE_STRTOK_R
209 char *strtok_r(char *, const char *, char **);
210 #endif
212 /* stdlib.h */
213 #ifndef HAVE_ATOF
214 #ifndef __ANDROID__
215 double atof (const char *);
216 #endif
217 #endif
219 #ifndef HAVE_ATOLL
220 long long atoll (const char *);
221 #endif
223 #ifndef HAVE_LLDIV
224 lldiv_t lldiv (long long, long long);
225 #endif
227 #ifndef HAVE_STRTOF
228 #ifndef __ANDROID__
229 float strtof (const char *, char **);
230 #endif
231 #endif
233 #ifndef HAVE_STRTOLL
234 long long int strtoll (const char *, char **, int);
235 #endif
237 /* time.h */
238 #ifndef HAVE_GMTIME_R
239 struct tm *gmtime_r (const time_t *, struct tm *);
240 #endif
242 #ifndef HAVE_LOCALTIME_R
243 struct tm *localtime_r (const time_t *, struct tm *);
244 #endif
246 #ifndef HAVE_TIMEGM
247 time_t timegm(struct tm *);
248 #endif
250 #ifndef HAVE_TIMESPEC_GET
251 #define TIME_UTC 1
252 struct timespec;
253 int timespec_get(struct timespec *, int);
254 #endif
256 /* sys/time.h */
257 #ifndef HAVE_GETTIMEOFDAY
258 struct timezone;
259 int gettimeofday(struct timeval *, struct timezone *);
260 #endif
262 /* unistd.h */
263 #ifndef HAVE_GETPID
264 pid_t getpid (void) VLC_NOTHROW;
265 #endif
267 #ifndef HAVE_FSYNC
268 int fsync (int fd);
269 #endif
271 #ifndef HAVE_PATHCONF
272 long pathconf (const char *path, int name);
273 #endif
275 /* dirent.h */
276 #ifndef HAVE_DIRFD
277 int (dirfd) (DIR *);
278 #endif
280 #ifndef HAVE_FDOPENDIR
281 DIR *fdopendir (int);
282 #endif
284 #ifdef __cplusplus
285 } /* extern "C" */
286 #endif
288 /* stdlib.h */
289 #ifndef HAVE_GETENV
290 static inline char *getenv (const char *name)
292 (void)name;
293 return NULL;
295 #endif
297 #ifndef HAVE_SETENV
298 int setenv (const char *, const char *, int);
299 int unsetenv (const char *);
300 #endif
302 #ifndef HAVE_ALIGNED_ALLOC
303 void *aligned_alloc(size_t, size_t);
304 #endif
306 #if defined (_WIN32) && defined(__MINGW32__)
307 #define aligned_free(ptr) __mingw_aligned_free(ptr)
308 #elif defined (_WIN32) && defined(_MSC_VER)
309 #define aligned_free(ptr) _aligned_free(ptr)
310 #else
311 #define aligned_free(ptr) free(ptr)
312 #endif
314 #if defined(__native_client__) && defined(__cplusplus)
315 # define HAVE_USELOCALE
316 #endif
318 #if !defined(HAVE_NEWLOCALE) && defined(HAVE_CXX_LOCALE_T) && defined(__cplusplus)
319 # include <locale>
320 # define HAVE_NEWLOCALE
321 #endif
323 /* locale.h */
324 #ifndef HAVE_USELOCALE
325 # ifndef HAVE_NEWLOCALE
326 # define LC_ALL_MASK 0
327 # define LC_NUMERIC_MASK 0
328 # define LC_MESSAGES_MASK 0
329 # define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
330 typedef void *locale_t;
332 static inline void freelocale(locale_t loc)
334 (void)loc;
336 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
338 (void)mask; (void)locale; (void)base;
339 return NULL;
341 # else
342 # include <locale.h>
343 # endif
345 static inline locale_t uselocale(locale_t loc)
347 (void)loc;
348 return NULL;
350 #endif
352 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
353 # define STATIC_ASSERT_CONCAT_(a, b) a##b
354 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
355 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
356 # define static_assert _Static_assert
357 #endif
359 /* libintl support */
360 #define _(str) vlc_gettext (str)
361 #define N_(str) gettext_noop (str)
362 #define gettext_noop(str) (str)
364 #ifdef __cplusplus
365 extern "C" {
366 #endif
368 #ifndef HAVE_SWAB
369 void swab (const void *, void *, ssize_t);
370 #endif
372 /* Socket stuff */
373 #ifndef HAVE_INET_PTON
374 # ifndef _WIN32
375 # include <sys/socket.h>
376 #else
377 typedef int socklen_t;
378 # endif
379 int inet_pton(int, const char *, void *);
380 const char *inet_ntop(int, const void *, char *, socklen_t);
381 #endif
383 /* NaCl has a broken netinet/tcp.h, so TCP_NODELAY is not set */
384 #if defined(__native_client__) && !defined( HAVE_NETINET_TCP_H )
385 # define TCP_NODELAY 1
386 #endif
388 #ifndef HAVE_STRUCT_POLLFD
389 enum
391 POLLERR=0x1,
392 POLLHUP=0x2,
393 POLLNVAL=0x4,
394 POLLWRNORM=0x10,
395 POLLWRBAND=0x20,
396 POLLRDNORM=0x100,
397 POLLRDBAND=0x200,
398 POLLPRI=0x400,
400 #define POLLIN (POLLRDNORM|POLLRDBAND)
401 #define POLLOUT (POLLWRNORM|POLLWRBAND)
403 struct pollfd
405 int fd;
406 short events;
407 short revents;
409 #endif
410 #ifndef HAVE_POLL
411 struct pollfd;
412 int poll (struct pollfd *, unsigned, int);
413 #endif
415 #ifndef HAVE_IF_NAMEINDEX
416 #include <errno.h>
417 # ifndef HAVE_STRUCT_IF_NAMEINDEX
418 struct if_nameindex
420 unsigned if_index;
421 char *if_name;
423 # endif
424 # define if_nameindex() (errno = ENOBUFS, NULL)
425 # define if_freenameindex(list) (void)0
426 #endif
428 #ifndef HAVE_STRUCT_TIMESPEC
429 struct timespec {
430 time_t tv_sec; /* Seconds */
431 long tv_nsec; /* Nanoseconds */
433 #endif
435 #ifdef _WIN32
436 struct iovec
438 void *iov_base;
439 size_t iov_len;
441 #define IOV_MAX 255
442 struct msghdr
444 void *msg_name;
445 size_t msg_namelen;
446 struct iovec *msg_iov;
447 size_t msg_iovlen;
448 void *msg_control;
449 size_t msg_controllen;
450 int msg_flags;
452 #endif
454 #ifdef _NEWLIB_VERSION
455 #define IOV_MAX 255
456 #endif
458 #ifndef HAVE_RECVMSG
459 struct msghdr;
460 ssize_t recvmsg(int, struct msghdr *, int);
461 #endif
463 #ifndef HAVE_SENDMSG
464 struct msghdr;
465 ssize_t sendmsg(int, const struct msghdr *, int);
466 #endif
468 /* search.h */
469 #ifndef HAVE_SEARCH_H
470 typedef struct entry {
471 char *key;
472 void *data;
473 } ENTRY;
475 typedef enum {
476 FIND, ENTER
477 } ACTION;
479 typedef enum {
480 preorder,
481 postorder,
482 endorder,
483 leaf
484 } VISIT;
486 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
487 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
488 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
489 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
490 void *lfind( const void *key, const void *base, size_t *nmemb,
491 size_t size, int(*cmp)(const void *, const void *) );
492 #endif /* HAVE_SEARCH_H */
493 #ifndef HAVE_TDESTROY
494 void tdestroy( void *root, void (*free_node)(void *nodep) );
495 #endif
497 /* Random numbers */
498 #ifndef HAVE_NRAND48
499 double erand48 (unsigned short subi[3]);
500 long jrand48 (unsigned short subi[3]);
501 long nrand48 (unsigned short subi[3]);
502 #endif
504 #ifdef __OS2__
505 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
507 # define SHUT_RD 0
508 # define SHUT_WR 1
509 # define SHUT_RDWR 2
511 /* GAI error codes */
512 # ifndef EAI_BADFLAGS
513 # define EAI_BADFLAGS -1
514 # endif
515 # ifndef EAI_NONAME
516 # define EAI_NONAME -2
517 # endif
518 # ifndef EAI_AGAIN
519 # define EAI_AGAIN -3
520 # endif
521 # ifndef EAI_FAIL
522 # define EAI_FAIL -4
523 # endif
524 # ifndef EAI_NODATA
525 # define EAI_NODATA -5
526 # endif
527 # ifndef EAI_FAMILY
528 # define EAI_FAMILY -6
529 # endif
530 # ifndef EAI_SOCKTYPE
531 # define EAI_SOCKTYPE -7
532 # endif
533 # ifndef EAI_SERVICE
534 # define EAI_SERVICE -8
535 # endif
536 # ifndef EAI_ADDRFAMILY
537 # define EAI_ADDRFAMILY -9
538 # endif
539 # ifndef EAI_MEMORY
540 # define EAI_MEMORY -10
541 # endif
542 # ifndef EAI_OVERFLOW
543 # define EAI_OVERFLOW -11
544 # endif
545 # ifndef EAI_SYSTEM
546 # define EAI_SYSTEM -12
547 # endif
549 # ifndef NI_NUMERICHOST
550 # define NI_NUMERICHOST 0x01
551 # define NI_NUMERICSERV 0x02
552 # define NI_NOFQDN 0x04
553 # define NI_NAMEREQD 0x08
554 # define NI_DGRAM 0x10
555 # endif
557 # ifndef NI_MAXHOST
558 # define NI_MAXHOST 1025
559 # define NI_MAXSERV 32
560 # endif
562 # define AI_PASSIVE 1
563 # define AI_CANONNAME 2
564 # define AI_NUMERICHOST 4
566 struct addrinfo
568 int ai_flags;
569 int ai_family;
570 int ai_socktype;
571 int ai_protocol;
572 size_t ai_addrlen;
573 struct sockaddr *ai_addr;
574 char *ai_canonname;
575 struct addrinfo *ai_next;
578 const char *gai_strerror (int);
580 int getaddrinfo (const char *node, const char *service,
581 const struct addrinfo *hints, struct addrinfo **res);
582 void freeaddrinfo (struct addrinfo *res);
583 int getnameinfo (const struct sockaddr *sa, socklen_t salen,
584 char *host, int hostlen, char *serv, int servlen,
585 int flags);
587 /* OS/2 does not support IPv6, yet. But declare these only for compilation */
588 # include <stdint.h>
590 struct in6_addr
592 uint8_t s6_addr[16];
595 struct sockaddr_in6
597 uint8_t sin6_len;
598 uint8_t sin6_family;
599 uint16_t sin6_port;
600 uint32_t sin6_flowinfo;
601 struct in6_addr sin6_addr;
602 uint32_t sin6_scope_id;
605 # define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
607 static const struct in6_addr in6addr_any =
608 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
610 # include <errno.h>
611 # ifndef EPROTO
612 # define EPROTO (ELAST + 1)
613 # endif
615 # ifndef HAVE_IF_NAMETOINDEX
616 # define if_nametoindex(name) atoi(name)
617 # endif
618 #endif
620 /* math.h */
622 #ifndef HAVE_NANF
623 #define nanf(tagp) NAN
624 #endif
626 #ifndef HAVE_SINCOS
627 void sincos(double, double *, double *);
628 void sincosf(float, float *, float *);
629 #endif
631 #ifndef HAVE_REALPATH
632 char *realpath(const char * restrict pathname, char * restrict resolved_path);
633 #endif
635 #ifdef _WIN32
636 FILE *vlc_win32_tmpfile(void);
637 #endif
639 /* mingw-w64 has a broken IN6_IS_ADDR_MULTICAST macro */
640 #if defined(_WIN32) && defined(__MINGW64_VERSION_MAJOR)
641 # define IN6_IS_ADDR_MULTICAST IN6_IS_ADDR_MULTICAST
642 #endif
644 #ifdef __APPLE__
645 # define fdatasync fsync
646 #endif
648 #ifdef __cplusplus
649 } /* extern "C" */
650 #endif
652 #endif /* !LIBVLC_FIXUPS_H */