codec: atsc_a65: avoid crash
[vlc.git] / include / vlc_fixups.h
blobeb0eb17278119d3f521a93f8a4421742074c0219
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__))
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_STRLCPY) || \
94 !defined (HAVE_STRNDUP) || \
95 !defined (HAVE_STRNLEN) || \
96 !defined (HAVE_STRNSTR)
97 # include <stddef.h> /* size_t */
98 #endif
100 #ifndef HAVE_VASPRINTF
101 # include <stdarg.h> /* va_list */
102 #endif
104 #if !defined (HAVE_GETDELIM) || \
105 !defined (HAVE_GETPID) || \
106 !defined (HAVE_SWAB)
107 # include <sys/types.h> /* ssize_t, pid_t */
108 #endif
110 #if !defined (HAVE_DIRFD) || \
111 !defined (HAVE_FDOPENDIR)
112 # include <dirent.h>
113 #endif
115 #ifdef __cplusplus
116 # define VLC_NOTHROW throw ()
117 extern "C" {
118 #else
119 # define VLC_NOTHROW
120 #endif
122 /* signal.h */
123 #if !defined(HAVE_SIGWAIT) && defined(__native_client__)
124 /* NaCl does not define sigwait in signal.h. We need to include it here to
125 * define sigwait, because sigset_t is allowed to be either an integral or a
126 * struct. */
127 #include <signal.h>
128 int sigwait(const sigset_t *set, int *sig);
129 #endif
131 /* stddef.h */
132 #if !defined (__cplusplus) && !defined (HAVE_MAX_ALIGN_T)
133 typedef struct {
134 long long ll;
135 long double ld;
136 } max_align_t;
137 #endif
139 /* stdio.h */
140 #ifndef HAVE_ASPRINTF
141 int asprintf (char **, const char *, ...);
142 #endif
144 #ifndef HAVE_FLOCKFILE
145 void flockfile (FILE *);
146 void funlockfile (FILE *);
147 int getc_unlocked (FILE *);
148 int getchar_unlocked (void);
149 int putc_unlocked (int, FILE *);
150 int putchar_unlocked (int);
151 #endif
153 #ifndef HAVE_GETDELIM
154 ssize_t getdelim (char **, size_t *, int, FILE *);
155 ssize_t getline (char **, size_t *, FILE *);
156 #endif
158 #ifndef HAVE_REWIND
159 void rewind (FILE *);
160 #endif
162 #ifndef HAVE_VASPRINTF
163 int vasprintf (char **, const char *, va_list);
164 #endif
166 /* string.h */
167 #ifndef HAVE_FFSLL
168 int ffsll(long long);
169 #endif
171 #ifndef HAVE_MEMRCHR
172 void *memrchr(const void *, int, size_t);
173 #endif
175 #ifndef HAVE_STRCASECMP
176 int strcasecmp (const char *, const char *);
177 #endif
179 #ifndef HAVE_STRCASESTR
180 char *strcasestr (const char *, const char *);
181 #endif
183 #ifndef HAVE_STRDUP
184 char *strdup (const char *);
185 #endif
187 #ifndef HAVE_STRVERSCMP
188 int strverscmp (const char *, const char *);
189 #endif
191 #ifndef HAVE_STRNLEN
192 size_t strnlen (const char *, size_t);
193 #endif
195 #ifndef HAVE_STRNSTR
196 char * strnstr (const char *, const char *, size_t);
197 #endif
199 #ifndef HAVE_STRNDUP
200 char *strndup (const char *, size_t);
201 #endif
203 #ifndef HAVE_STRLCPY
204 size_t strlcpy (char *, const char *, size_t);
205 #endif
207 #ifndef HAVE_STRSEP
208 char *strsep (char **, const char *);
209 #endif
211 #ifndef HAVE_STRTOK_R
212 char *strtok_r(char *, const char *, char **);
213 #endif
215 /* stdlib.h */
216 #ifndef HAVE_ATOF
217 #ifndef __ANDROID__
218 double atof (const char *);
219 #endif
220 #endif
222 #ifndef HAVE_ATOLL
223 long long atoll (const char *);
224 #endif
226 #ifndef HAVE_LLDIV
227 lldiv_t lldiv (long long, long long);
228 #endif
230 #ifndef HAVE_STRTOF
231 #ifndef __ANDROID__
232 float strtof (const char *, char **);
233 #endif
234 #endif
236 #ifndef HAVE_STRTOLL
237 long long int strtoll (const char *, char **, int);
238 #endif
240 /* time.h */
241 #ifndef HAVE_GMTIME_R
242 struct tm *gmtime_r (const time_t *, struct tm *);
243 #endif
245 #ifndef HAVE_LOCALTIME_R
246 struct tm *localtime_r (const time_t *, struct tm *);
247 #endif
249 #ifndef HAVE_TIMEGM
250 time_t timegm(struct tm *);
251 #endif
253 #ifndef HAVE_TIMESPEC_GET
254 #define TIME_UTC 1
255 struct timespec;
256 int timespec_get(struct timespec *, int);
257 #endif
259 /* sys/time.h */
260 #ifndef HAVE_GETTIMEOFDAY
261 struct timezone;
262 int gettimeofday(struct timeval *, struct timezone *);
263 #endif
265 /* unistd.h */
266 #ifndef HAVE_GETPID
267 pid_t getpid (void) VLC_NOTHROW;
268 #endif
270 #ifndef HAVE_FSYNC
271 int fsync (int fd);
272 #endif
274 #ifndef HAVE_PATHCONF
275 long pathconf (const char *path, int name);
276 #endif
278 /* dirent.h */
279 #ifndef HAVE_DIRFD
280 int (dirfd) (DIR *);
281 #endif
283 #ifndef HAVE_FDOPENDIR
284 DIR *fdopendir (int);
285 #endif
287 #ifdef __cplusplus
288 } /* extern "C" */
289 #endif
291 /* stdlib.h */
292 #ifndef HAVE_GETENV
293 static inline char *getenv (const char *name)
295 (void)name;
296 return NULL;
298 #endif
300 #ifndef HAVE_SETENV
301 int setenv (const char *, const char *, int);
302 int unsetenv (const char *);
303 #endif
305 #ifndef HAVE_ALIGNED_ALLOC
306 void *aligned_alloc(size_t, size_t);
307 #endif
309 #if defined (_WIN32) && defined(__MINGW32__)
310 #define aligned_free(ptr) __mingw_aligned_free(ptr)
311 #elif defined (_WIN32) && defined(_MSC_VER)
312 #define aligned_free(ptr) _aligned_free(ptr)
313 #else
314 #define aligned_free(ptr) free(ptr)
315 #endif
317 #if defined(__native_client__) && defined(__cplusplus)
318 # define HAVE_USELOCALE
319 #endif
321 /* locale.h */
322 #ifndef HAVE_USELOCALE
323 #define LC_ALL_MASK 0
324 #define LC_NUMERIC_MASK 0
325 #define LC_MESSAGES_MASK 0
326 #define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
327 typedef void *locale_t;
328 static inline locale_t uselocale(locale_t loc)
330 (void)loc;
331 return NULL;
333 static inline void freelocale(locale_t loc)
335 (void)loc;
337 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
339 (void)mask; (void)locale; (void)base;
340 return NULL;
342 #endif
344 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
345 # define STATIC_ASSERT_CONCAT_(a, b) a##b
346 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
347 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
348 # define static_assert _Static_assert
349 #endif
351 /* libintl support */
352 #define _(str) vlc_gettext (str)
353 #define N_(str) gettext_noop (str)
354 #define gettext_noop(str) (str)
356 #ifdef __cplusplus
357 extern "C" {
358 #endif
360 #ifndef HAVE_SWAB
361 void swab (const void *, void *, ssize_t);
362 #endif
364 /* Socket stuff */
365 #ifndef HAVE_INET_PTON
366 # ifndef _WIN32
367 # include <sys/socket.h>
368 #else
369 typedef int socklen_t;
370 # endif
371 int inet_pton(int, const char *, void *);
372 const char *inet_ntop(int, const void *, char *, socklen_t);
373 #endif
375 /* NaCl has a broken netinet/tcp.h, so TCP_NODELAY is not set */
376 #if defined(__native_client__) && !defined( HAVE_NETINET_TCP_H )
377 # define TCP_NODELAY 1
378 #endif
380 #ifndef HAVE_STRUCT_POLLFD
381 enum
383 POLLERR=0x1,
384 POLLHUP=0x2,
385 POLLNVAL=0x4,
386 POLLWRNORM=0x10,
387 POLLWRBAND=0x20,
388 POLLRDNORM=0x100,
389 POLLRDBAND=0x200,
390 POLLPRI=0x400,
392 #define POLLIN (POLLRDNORM|POLLRDBAND)
393 #define POLLOUT (POLLWRNORM|POLLWRBAND)
395 struct pollfd
397 int fd;
398 unsigned events;
399 unsigned revents;
401 #endif
402 #ifndef HAVE_POLL
403 struct pollfd;
404 int poll (struct pollfd *, unsigned, int);
405 #endif
407 #ifndef HAVE_IF_NAMEINDEX
408 #include <errno.h>
409 struct if_nameindex
411 unsigned if_index;
412 char *if_name;
414 # ifndef HAVE_IF_NAMETOINDEX
415 # define if_nametoindex(name) atoi(name)
416 # endif
417 # define if_nameindex() (errno = ENOBUFS, NULL)
418 # define if_freenameindex(list) (void)0
419 #endif
421 #ifndef HAVE_STRUCT_TIMESPEC
422 struct timespec {
423 time_t tv_sec; /* Seconds */
424 long tv_nsec; /* Nanoseconds */
426 #endif
428 #ifdef _WIN32
429 struct iovec
431 void *iov_base;
432 size_t iov_len;
434 #define IOV_MAX 255
435 struct msghdr
437 void *msg_name;
438 size_t msg_namelen;
439 struct iovec *msg_iov;
440 size_t msg_iovlen;
441 void *msg_control;
442 size_t msg_controllen;
443 int msg_flags;
445 #endif
447 #ifdef _NEWLIB_VERSION
448 #define IOV_MAX 255
449 #endif
451 #ifndef HAVE_RECVMSG
452 struct msghdr;
453 ssize_t recvmsg(int, struct msghdr *, int);
454 #endif
456 #ifndef HAVE_SENDMSG
457 struct msghdr;
458 ssize_t sendmsg(int, const struct msghdr *, int);
459 #endif
461 /* search.h */
462 #ifndef HAVE_SEARCH_H
463 typedef struct entry {
464 char *key;
465 void *data;
466 } ENTRY;
468 typedef enum {
469 FIND, ENTER
470 } ACTION;
472 typedef enum {
473 preorder,
474 postorder,
475 endorder,
476 leaf
477 } VISIT;
479 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
480 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
481 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
482 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
483 void tdestroy( void *root, void (*free_node)(void *nodep) );
484 #else // HAVE_SEARCH_H
485 # ifndef HAVE_TDESTROY
486 void vlc_tdestroy( void *, void (*)(void *) );
487 # define tdestroy vlc_tdestroy
488 # endif
489 #endif
491 /* Random numbers */
492 #ifndef HAVE_NRAND48
493 double erand48 (unsigned short subi[3]);
494 long jrand48 (unsigned short subi[3]);
495 long nrand48 (unsigned short subi[3]);
496 #endif
498 #ifdef __OS2__
499 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
501 # define SHUT_RD 0
502 # define SHUT_WR 1
503 # define SHUT_RDWR 2
505 /* GAI error codes */
506 # ifndef EAI_BADFLAGS
507 # define EAI_BADFLAGS -1
508 # endif
509 # ifndef EAI_NONAME
510 # define EAI_NONAME -2
511 # endif
512 # ifndef EAI_AGAIN
513 # define EAI_AGAIN -3
514 # endif
515 # ifndef EAI_FAIL
516 # define EAI_FAIL -4
517 # endif
518 # ifndef EAI_NODATA
519 # define EAI_NODATA -5
520 # endif
521 # ifndef EAI_FAMILY
522 # define EAI_FAMILY -6
523 # endif
524 # ifndef EAI_SOCKTYPE
525 # define EAI_SOCKTYPE -7
526 # endif
527 # ifndef EAI_SERVICE
528 # define EAI_SERVICE -8
529 # endif
530 # ifndef EAI_ADDRFAMILY
531 # define EAI_ADDRFAMILY -9
532 # endif
533 # ifndef EAI_MEMORY
534 # define EAI_MEMORY -10
535 # endif
536 # ifndef EAI_OVERFLOW
537 # define EAI_OVERFLOW -11
538 # endif
539 # ifndef EAI_SYSTEM
540 # define EAI_SYSTEM -12
541 # endif
543 # ifndef NI_NUMERICHOST
544 # define NI_NUMERICHOST 0x01
545 # define NI_NUMERICSERV 0x02
546 # define NI_NOFQDN 0x04
547 # define NI_NAMEREQD 0x08
548 # define NI_DGRAM 0x10
549 # endif
551 # ifndef NI_MAXHOST
552 # define NI_MAXHOST 1025
553 # define NI_MAXSERV 32
554 # endif
556 # define AI_PASSIVE 1
557 # define AI_CANONNAME 2
558 # define AI_NUMERICHOST 4
560 struct addrinfo
562 int ai_flags;
563 int ai_family;
564 int ai_socktype;
565 int ai_protocol;
566 size_t ai_addrlen;
567 struct sockaddr *ai_addr;
568 char *ai_canonname;
569 struct addrinfo *ai_next;
572 const char *gai_strerror (int);
574 int getaddrinfo (const char *node, const char *service,
575 const struct addrinfo *hints, struct addrinfo **res);
576 void freeaddrinfo (struct addrinfo *res);
577 int getnameinfo (const struct sockaddr *sa, socklen_t salen,
578 char *host, int hostlen, char *serv, int servlen,
579 int flags);
581 /* OS/2 does not support IPv6, yet. But declare these only for compilation */
582 # include <stdint.h>
584 struct in6_addr
586 uint8_t s6_addr[16];
589 struct sockaddr_in6
591 uint8_t sin6_len;
592 uint8_t sin6_family;
593 uint16_t sin6_port;
594 uint32_t sin6_flowinfo;
595 struct in6_addr sin6_addr;
596 uint32_t sin6_scope_id;
599 # define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
601 static const struct in6_addr in6addr_any =
602 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
604 # include <errno.h>
605 # ifndef EPROTO
606 # define EPROTO (ELAST + 1)
607 # endif
608 #endif
610 /* math.h */
612 #ifndef HAVE_NANF
613 #define nanf(tagp) NAN
614 #endif
616 #ifndef HAVE_SINCOS
617 void sincos(double, double *, double *);
618 void sincosf(float, float *, float *);
619 #endif
621 #ifndef HAVE_REALPATH
622 char *realpath(const char * restrict pathname, char * restrict resolved_path);
623 #endif
625 #ifdef _WIN32
626 FILE *vlc_win32_tmpfile(void);
627 #endif
629 /* mingw-w64 has a broken IN6_IS_ADDR_MULTICAST macro */
630 #if defined(_WIN32) && defined(__MINGW64_VERSION_MAJOR)
631 # define IN6_IS_ADDR_MULTICAST IN6_IS_ADDR_MULTICAST
632 #endif
634 #ifdef __APPLE__
635 # define fdatasync fsync
636 #endif
638 #ifdef __cplusplus
639 } /* extern "C" */
640 #endif
642 #endif /* !LIBVLC_FIXUPS_H */