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__))
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
48 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R) \
49 || !defined (HAVE_TIMEGM)
50 # include <time.h> /* time_t */
53 #ifndef HAVE_GETTIMEOFDAY
64 long long quot
; /* Quotient. */
65 long long rem
; /* Remainder. */
69 #if !defined(HAVE_GETENV) || \
70 !defined(HAVE_USELOCALE)
71 # include <stddef.h> /* NULL */
74 #if !defined (HAVE_REWIND) || \
75 !defined (HAVE_GETDELIM)
76 # include <stdio.h> /* FILE */
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 */
88 #ifndef HAVE_VASPRINTF
89 # include <stdarg.h> /* va_list */
92 #if !defined (HAVE_GETDELIM) || \
93 !defined (HAVE_GETPID) || \
95 # include <sys/types.h> /* ssize_t, pid_t */
98 #if !defined (HAVE_DIRFD) || \
99 !defined (HAVE_FDOPENDIR)
104 # define VLC_NOTHROW throw ()
111 #if !defined (__cplusplus) && !defined (HAVE_MAX_ALIGN_T)
119 #ifndef HAVE_ASPRINTF
120 int asprintf (char **, const char *, ...);
123 #ifndef HAVE_FLOCKFILE
124 void flockfile (FILE *);
125 void funlockfile (FILE *);
126 int getc_unlocked (FILE *);
127 int getchar_unlocked (void);
128 int putc_unlocked (int, FILE *);
129 int putchar_unlocked (int);
132 #ifndef HAVE_GETDELIM
133 ssize_t
getdelim (char **, size_t *, int, FILE *);
134 ssize_t
getline (char **, size_t *, FILE *);
138 void rewind (FILE *);
141 #ifndef HAVE_VASPRINTF
142 int vasprintf (char **, const char *, va_list);
147 int ffsll(long long);
151 void *memrchr(const void *, int, size_t);
154 #ifndef HAVE_STRCASECMP
155 int strcasecmp (const char *, const char *);
158 #ifndef HAVE_STRCASESTR
159 char *strcasestr (const char *, const char *);
163 char *strdup (const char *);
166 #ifndef HAVE_STRVERSCMP
167 int strverscmp (const char *, const char *);
171 size_t strnlen (const char *, size_t);
175 char * strnstr (const char *, const char *, size_t);
179 char *strndup (const char *, size_t);
183 size_t strlcpy (char *, const char *, size_t);
187 char *strsep (char **, const char *);
190 #ifndef HAVE_STRTOK_R
191 char *strtok_r(char *, const char *, char **);
197 double atof (const char *);
202 long long atoll (const char *);
206 lldiv_t
lldiv (long long, long long);
211 float strtof (const char *, char **);
216 long long int strtoll (const char *, char **, int);
220 #ifndef HAVE_GMTIME_R
221 struct tm
*gmtime_r (const time_t *, struct tm
*);
224 #ifndef HAVE_LOCALTIME_R
225 struct tm
*localtime_r (const time_t *, struct tm
*);
229 time_t timegm(struct tm
*);
232 #ifndef HAVE_TIMESPEC_GET
235 int timespec_get(struct timespec
*, int);
239 #ifndef HAVE_GETTIMEOFDAY
241 int gettimeofday(struct timeval
*, struct timezone
*);
246 pid_t
getpid (void) VLC_NOTHROW
;
258 #ifndef HAVE_FDOPENDIR
259 DIR *fdopendir (int);
268 static inline char *getenv (const char *name
)
276 int setenv (const char *, const char *, int);
277 int unsetenv (const char *);
280 #ifndef HAVE_POSIX_MEMALIGN
281 int posix_memalign (void **, size_t, size_t);
285 #ifndef HAVE_USELOCALE
286 #define LC_ALL_MASK 0
287 #define LC_NUMERIC_MASK 0
288 #define LC_MESSAGES_MASK 0
289 #define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
290 typedef void *locale_t
;
291 static inline locale_t
uselocale(locale_t loc
)
296 static inline void freelocale(locale_t loc
)
300 static inline locale_t
newlocale(int mask
, const char * locale
, locale_t base
)
302 (void)mask
; (void)locale
; (void)base
;
307 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
308 # define STATIC_ASSERT_CONCAT_(a, b) a##b
309 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
310 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
311 # define static_assert _Static_assert
314 /* Alignment of critical static data structures */
315 #ifdef ATTRIBUTE_ALIGNED_MAX
316 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
318 # define ATTR_ALIGN(align)
321 /* libintl support */
322 #define _(str) vlc_gettext (str)
323 #define N_(str) gettext_noop (str)
324 #define gettext_noop(str) (str)
331 void swab (const void *, void *, ssize_t
);
335 #ifndef HAVE_INET_PTON
337 # include <sys/socket.h>
339 typedef int socklen_t
;
341 int inet_pton(int, const char *, void *);
342 const char *inet_ntop(int, const void *, char *, socklen_t
);
345 #ifndef HAVE_STRUCT_POLLFD
357 #define POLLIN (POLLRDNORM|POLLRDBAND)
358 #define POLLOUT (POLLWRNORM|POLLWRBAND)
369 int poll (struct pollfd
*, unsigned, int);
372 #ifndef HAVE_IF_NAMEINDEX
379 # ifndef HAVE_IF_NAMETOINDEX
380 # define if_nametoindex(name) atoi(name)
382 # define if_nameindex() (errno = ENOBUFS, NULL)
383 # define if_freenameindex(list) (void)0
386 #ifndef HAVE_STRUCT_TIMESPEC
388 time_t tv_sec
; /* Seconds */
389 long tv_nsec
; /* Nanoseconds */
404 struct iovec
*msg_iov
;
407 size_t msg_controllen
;
414 ssize_t
recvmsg(int, struct msghdr
*, int);
419 ssize_t
sendmsg(int, const struct msghdr
*, int);
423 #ifndef HAVE_SEARCH_H
424 typedef struct entry
{
440 void *tsearch( const void *key
, void **rootp
, int(*cmp
)(const void *, const void *) );
441 void *tfind( const void *key
, const void **rootp
, int(*cmp
)(const void *, const void *) );
442 void *tdelete( const void *key
, void **rootp
, int(*cmp
)(const void *, const void *) );
443 void twalk( const void *root
, void(*action
)(const void *nodep
, VISIT which
, int depth
) );
444 void tdestroy( void *root
, void (*free_node
)(void *nodep
) );
445 #else // HAVE_SEARCH_H
446 # ifndef HAVE_TDESTROY
447 void vlc_tdestroy( void *, void (*)(void *) );
448 # define tdestroy vlc_tdestroy
454 double erand48 (unsigned short subi
[3]);
455 long jrand48 (unsigned short subi
[3]);
456 long nrand48 (unsigned short subi
[3]);
460 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
469 struct sockaddr
*ai_addr
;
471 struct addrinfo
*ai_next
;
474 void freeaddrinfo (struct addrinfo
*res
);
478 # define EPROTO (ELAST + 1)
485 #define nanf(tagp) NAN
489 void sincos(double, double *, double *);
490 void sincosf(float, float *, float *);
493 #ifndef HAVE_REALPATH
494 char *realpath(const char * restrict pathname
, char * restrict resolved_path
);
498 FILE *vlc_win32_tmpfile(void);
501 /* mingw-w64 has a broken IN6_IS_ADDR_MULTICAST macro */
502 #if defined(_WIN32) && defined(__MINGW64_VERSION_MAJOR)
503 # define IN6_IS_ADDR_MULTICAST IN6_IS_ADDR_MULTICAST
507 # define fdatasync fsync
514 #endif /* !LIBVLC_FIXUPS_H */