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 *****************************************************************************/
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
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
40 # ifndef __STDC_CONSTANT_MACROS
41 # define __STDC_CONSTANT_MACROS 1
43 # ifndef __STDC_LIMIT_MACROS
44 # define __STDC_LIMIT_MACROS 1
49 # ifdef HAVE_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)
60 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R) \
61 || !defined (HAVE_TIMEGM)
62 # include <time.h> /* time_t */
65 #ifndef HAVE_GETTIMEOFDAY
76 long long quot
; /* Quotient. */
77 long long rem
; /* Remainder. */
81 #if !defined(HAVE_GETENV) || \
82 !defined(HAVE_USELOCALE)
83 # include <stddef.h> /* NULL */
86 #if !defined (HAVE_REWIND) || \
87 !defined (HAVE_GETDELIM)
88 # include <stdio.h> /* FILE */
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 */
100 #ifndef HAVE_VASPRINTF
101 # include <stdarg.h> /* va_list */
104 #if !defined (HAVE_GETDELIM) || \
105 !defined (HAVE_GETPID) || \
107 # include <sys/types.h> /* ssize_t, pid_t */
110 #if !defined (HAVE_DIRFD) || \
111 !defined (HAVE_FDOPENDIR)
116 # define VLC_NOTHROW throw ()
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
128 int sigwait(const sigset_t
*set
, int *sig
);
132 #if !defined (__cplusplus) && !defined (HAVE_MAX_ALIGN_T)
140 #ifndef HAVE_ASPRINTF
141 int asprintf (char **, const char *, ...);
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);
153 #ifndef HAVE_GETDELIM
154 ssize_t
getdelim (char **, size_t *, int, FILE *);
155 ssize_t
getline (char **, size_t *, FILE *);
159 void rewind (FILE *);
162 #ifndef HAVE_VASPRINTF
163 int vasprintf (char **, const char *, va_list);
168 void *memrchr(const void *, int, size_t);
171 #ifndef HAVE_STRCASECMP
172 int strcasecmp (const char *, const char *);
175 #ifndef HAVE_STRCASESTR
176 char *strcasestr (const char *, const char *);
180 char *strdup (const char *);
183 #ifndef HAVE_STRVERSCMP
184 int strverscmp (const char *, const char *);
188 size_t strnlen (const char *, size_t);
192 char * strnstr (const char *, const char *, size_t);
196 char *strndup (const char *, size_t);
200 size_t strlcpy (char *, const char *, size_t);
204 char *strsep (char **, const char *);
207 #ifndef HAVE_STRTOK_R
208 char *strtok_r(char *, const char *, char **);
214 double atof (const char *);
219 long long atoll (const char *);
223 lldiv_t
lldiv (long long, long long);
228 float strtof (const char *, char **);
233 long long int strtoll (const char *, char **, int);
237 #ifndef HAVE_GMTIME_R
238 struct tm
*gmtime_r (const time_t *, struct tm
*);
241 #ifndef HAVE_LOCALTIME_R
242 struct tm
*localtime_r (const time_t *, struct tm
*);
246 time_t timegm(struct tm
*);
249 #ifndef HAVE_TIMESPEC_GET
252 int timespec_get(struct timespec
*, int);
256 #ifndef HAVE_GETTIMEOFDAY
258 int gettimeofday(struct timeval
*, struct timezone
*);
263 pid_t
getpid (void) VLC_NOTHROW
;
270 #ifndef HAVE_PATHCONF
271 long pathconf (const char *path
, int name
);
279 #ifndef HAVE_FDOPENDIR
280 DIR *fdopendir (int);
289 static inline char *getenv (const char *name
)
297 int setenv (const char *, const char *, int);
298 int unsetenv (const char *);
301 #ifndef HAVE_ALIGNED_ALLOC
302 void *aligned_alloc(size_t, size_t);
305 #if defined (_WIN32) && defined(__MINGW32__)
306 #define aligned_free(ptr) __mingw_aligned_free(ptr)
307 #elif defined (_WIN32) && defined(_MSC_VER)
308 #define aligned_free(ptr) _aligned_free(ptr)
310 #define aligned_free(ptr) free(ptr)
313 #if defined(__native_client__) && defined(__cplusplus)
314 # define HAVE_USELOCALE
317 #if !defined(HAVE_NEWLOCALE) && defined(HAVE_CXX_LOCALE_T) && defined(__cplusplus)
319 # define HAVE_NEWLOCALE
323 #ifndef HAVE_USELOCALE
324 # ifndef HAVE_NEWLOCALE
325 # define LC_ALL_MASK 0
326 # define LC_NUMERIC_MASK 0
327 # define LC_MESSAGES_MASK 0
328 # define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
329 typedef void *locale_t
;
331 static inline void freelocale(locale_t loc
)
335 static inline locale_t
newlocale(int mask
, const char * locale
, locale_t base
)
337 (void)mask
; (void)locale
; (void)base
;
344 static inline locale_t
uselocale(locale_t loc
)
351 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
352 # define STATIC_ASSERT_CONCAT_(a, b) a##b
353 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
354 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
355 # define static_assert _Static_assert
358 /* libintl support */
359 #define _(str) vlc_gettext (str)
360 #define N_(str) gettext_noop (str)
361 #define gettext_noop(str) (str)
368 void swab (const void *, void *, ssize_t
);
372 #ifndef HAVE_INET_PTON
374 # include <sys/socket.h>
376 typedef int socklen_t
;
378 int inet_pton(int, const char *, void *);
379 const char *inet_ntop(int, const void *, char *, socklen_t
);
382 /* NaCl has a broken netinet/tcp.h, so TCP_NODELAY is not set */
383 #if defined(__native_client__) && !defined( HAVE_NETINET_TCP_H )
384 # define TCP_NODELAY 1
387 #ifndef HAVE_STRUCT_POLLFD
399 #define POLLIN (POLLRDNORM|POLLRDBAND)
400 #define POLLOUT (POLLWRNORM|POLLWRBAND)
411 int poll (struct pollfd
*, unsigned, int);
414 #ifndef HAVE_IF_NAMEINDEX
421 # define if_nameindex() (errno = ENOBUFS, NULL)
422 # define if_freenameindex(list) (void)0
425 #ifndef HAVE_STRUCT_TIMESPEC
427 time_t tv_sec
; /* Seconds */
428 long tv_nsec
; /* Nanoseconds */
443 struct iovec
*msg_iov
;
446 size_t msg_controllen
;
451 #ifdef _NEWLIB_VERSION
457 ssize_t
recvmsg(int, struct msghdr
*, int);
462 ssize_t
sendmsg(int, const struct msghdr
*, int);
466 #ifndef HAVE_SEARCH_H
467 typedef struct entry
{
483 void *tsearch( const void *key
, void **rootp
, int(*cmp
)(const void *, const void *) );
484 void *tfind( const void *key
, const void **rootp
, int(*cmp
)(const void *, const void *) );
485 void *tdelete( const void *key
, void **rootp
, int(*cmp
)(const void *, const void *) );
486 void twalk( const void *root
, void(*action
)(const void *nodep
, VISIT which
, int depth
) );
487 #endif /* HAVE_SEARCH_H */
488 #ifndef HAVE_TDESTROY
489 void tdestroy( void *root
, void (*free_node
)(void *nodep
) );
494 double erand48 (unsigned short subi
[3]);
495 long jrand48 (unsigned short subi
[3]);
496 long nrand48 (unsigned short subi
[3]);
500 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
506 /* GAI error codes */
507 # ifndef EAI_BADFLAGS
508 # define EAI_BADFLAGS -1
511 # define EAI_NONAME -2
514 # define EAI_AGAIN -3
520 # define EAI_NODATA -5
523 # define EAI_FAMILY -6
525 # ifndef EAI_SOCKTYPE
526 # define EAI_SOCKTYPE -7
529 # define EAI_SERVICE -8
531 # ifndef EAI_ADDRFAMILY
532 # define EAI_ADDRFAMILY -9
535 # define EAI_MEMORY -10
537 # ifndef EAI_OVERFLOW
538 # define EAI_OVERFLOW -11
541 # define EAI_SYSTEM -12
544 # ifndef NI_NUMERICHOST
545 # define NI_NUMERICHOST 0x01
546 # define NI_NUMERICSERV 0x02
547 # define NI_NOFQDN 0x04
548 # define NI_NAMEREQD 0x08
549 # define NI_DGRAM 0x10
553 # define NI_MAXHOST 1025
554 # define NI_MAXSERV 32
557 # define AI_PASSIVE 1
558 # define AI_CANONNAME 2
559 # define AI_NUMERICHOST 4
568 struct sockaddr
*ai_addr
;
570 struct addrinfo
*ai_next
;
573 const char *gai_strerror (int);
575 int getaddrinfo (const char *node
, const char *service
,
576 const struct addrinfo
*hints
, struct addrinfo
**res
);
577 void freeaddrinfo (struct addrinfo
*res
);
578 int getnameinfo (const struct sockaddr
*sa
, socklen_t salen
,
579 char *host
, int hostlen
, char *serv
, int servlen
,
582 /* OS/2 does not support IPv6, yet. But declare these only for compilation */
595 uint32_t sin6_flowinfo
;
596 struct in6_addr sin6_addr
;
597 uint32_t sin6_scope_id
;
600 # define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
602 static const struct in6_addr in6addr_any
=
603 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
607 # define EPROTO (ELAST + 1)
610 # ifndef HAVE_IF_NAMETOINDEX
611 # define if_nametoindex(name) atoi(name)
618 #define nanf(tagp) NAN
622 void sincos(double, double *, double *);
623 void sincosf(float, float *, float *);
626 #ifndef HAVE_REALPATH
627 char *realpath(const char * restrict pathname
, char * restrict resolved_path
);
631 FILE *vlc_win32_tmpfile(void);
634 /* mingw-w64 has a broken IN6_IS_ADDR_MULTICAST macro */
635 #if defined(_WIN32) && defined(__MINGW64_VERSION_MAJOR)
636 # define IN6_IS_ADDR_MULTICAST IN6_IS_ADDR_MULTICAST
640 # define fdatasync fsync
647 #endif /* !LIBVLC_FIXUPS_H */