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(HAVE_CXX11) || 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 #ifndef HAVE_ASPRINTF
112 int asprintf (char **, const char *, ...);
115 #ifndef HAVE_FLOCKFILE
116 void flockfile (FILE *);
117 int ftrylockfile (FILE *);
118 void funlockfile (FILE *);
119 int getc_unlocked (FILE *);
120 int getchar_unlocked (void);
121 int putc_unlocked (int, FILE *);
122 int putchar_unlocked (int);
125 #ifndef HAVE_GETDELIM
126 ssize_t
getdelim (char **, size_t *, int, FILE *);
127 ssize_t
getline (char **, size_t *, FILE *);
131 void rewind (FILE *);
134 #ifndef HAVE_VASPRINTF
135 int vasprintf (char **, const char *, va_list);
140 int ffsll(unsigned long long);
144 void *memrchr(const void *, int, size_t);
147 #ifndef HAVE_STRCASECMP
148 int strcasecmp (const char *, const char *);
151 #ifndef HAVE_STRCASESTR
152 char *strcasestr (const char *, const char *);
156 char *strdup (const char *);
159 #ifndef HAVE_STRVERSCMP
160 int strverscmp (const char *, const char *);
164 size_t strnlen (const char *, size_t);
168 char * strnstr (const char *, const char *, size_t);
172 char *strndup (const char *, size_t);
176 size_t strlcpy (char *, const char *, size_t);
180 char *strsep (char **, const char *);
183 #ifndef HAVE_STRTOK_R
184 char *strtok_r(char *, const char *, char **);
190 double atof (const char *);
195 long long atoll (const char *);
199 lldiv_t
lldiv (long long, long long);
204 float strtof (const char *, char **);
209 long long int strtoll (const char *, char **, int);
213 #ifndef HAVE_GMTIME_R
214 struct tm
*gmtime_r (const time_t *, struct tm
*);
217 #ifndef HAVE_LOCALTIME_R
218 struct tm
*localtime_r (const time_t *, struct tm
*);
222 time_t timegm(struct tm
*);
225 #ifndef HAVE_TIMESPEC_GET
228 int timespec_get(struct timespec
*, int);
232 #ifndef HAVE_GETTIMEOFDAY
234 int gettimeofday(struct timeval
*, struct timezone
*);
239 pid_t
getpid (void) VLC_NOTHROW
;
251 #ifndef HAVE_FDOPENDIR
252 DIR *fdopendir (int);
261 static inline char *getenv (const char *name
)
269 int setenv (const char *, const char *, int);
270 int unsetenv (const char *);
273 #ifndef HAVE_POSIX_MEMALIGN
274 int posix_memalign (void **, size_t, size_t);
278 #ifndef HAVE_USELOCALE
279 #define LC_ALL_MASK 0
280 #define LC_NUMERIC_MASK 0
281 #define LC_MESSAGES_MASK 0
282 #define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
283 typedef void *locale_t
;
284 static inline locale_t
uselocale(locale_t loc
)
289 static inline void freelocale(locale_t loc
)
293 static inline locale_t
newlocale(int mask
, const char * locale
, locale_t base
)
295 (void)mask
; (void)locale
; (void)base
;
300 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
301 # define STATIC_ASSERT_CONCAT_(a, b) a##b
302 # define STATIC_ASSERT_CONCAT(a, b) STATIC_ASSERT_CONCAT_(a, b)
303 # define _Static_assert(x, s) extern char STATIC_ASSERT_CONCAT(static_assert_, __LINE__)[sizeof(struct { unsigned:-!(x); })]
304 # define static_assert _Static_assert
307 /* Alignment of critical static data structures */
308 #ifdef ATTRIBUTE_ALIGNED_MAX
309 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
311 # define ATTR_ALIGN(align)
314 /* libintl support */
315 #define _(str) vlc_gettext (str)
316 #define N_(str) gettext_noop (str)
317 #define gettext_noop(str) (str)
324 void swab (const void *, void *, ssize_t
);
328 #ifndef HAVE_INET_PTON
330 # include <sys/socket.h>
332 typedef int socklen_t
;
334 int inet_pton(int, const char *, void *);
335 const char *inet_ntop(int, const void *, char *, socklen_t
);
338 #ifndef HAVE_STRUCT_POLLFD
350 #define POLLIN (POLLRDNORM|POLLRDBAND)
351 #define POLLOUT (POLLWRNORM|POLLWRBAND)
362 int poll (struct pollfd
*, unsigned, int);
365 #ifndef HAVE_IF_NAMEINDEX
372 # ifndef HAVE_IF_NAMETOINDEX
373 # define if_nametoindex(name) atoi(name)
375 # define if_nameindex() (errno = ENOBUFS, NULL)
376 # define if_freenameindex(list) (void)0
379 #ifndef HAVE_STRUCT_TIMESPEC
381 time_t tv_sec
; /* Seconds */
382 long tv_nsec
; /* Nanoseconds */
397 struct iovec
*msg_iov
;
400 size_t msg_controllen
;
407 ssize_t
recvmsg(int, struct msghdr
*, int);
412 ssize_t
sendmsg(int, const struct msghdr
*, int);
416 #ifndef HAVE_SEARCH_H
417 typedef struct entry
{
433 void *tsearch( const void *key
, void **rootp
, int(*cmp
)(const void *, const void *) );
434 void *tfind( const void *key
, const void **rootp
, int(*cmp
)(const void *, const void *) );
435 void *tdelete( const void *key
, void **rootp
, int(*cmp
)(const void *, const void *) );
436 void twalk( const void *root
, void(*action
)(const void *nodep
, VISIT which
, int depth
) );
437 void tdestroy( void *root
, void (*free_node
)(void *nodep
) );
438 #else // HAVE_SEARCH_H
439 # ifndef HAVE_TDESTROY
440 void vlc_tdestroy( void *, void (*)(void *) );
441 # define tdestroy vlc_tdestroy
447 double erand48 (unsigned short subi
[3]);
448 long jrand48 (unsigned short subi
[3]);
449 long nrand48 (unsigned short subi
[3]);
453 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
462 struct sockaddr
*ai_addr
;
464 struct addrinfo
*ai_next
;
467 void freeaddrinfo (struct addrinfo
*res
);
473 #define nanf(tagp) NAN
477 FILE *vlc_win32_tmpfile(void);
484 #endif /* !LIBVLC_FIXUPS_H */