compat: remove 'const' from the prototype of timegm().
[vlc.git] / include / vlc_fixups.h
blob213d3f32adcdc6703984bb42d75c756fccd3879c
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 /* C++11 says there's no need to define __STDC_*_MACROS when including
30 * inttypes.h and stdint.h. */
31 #if defined (__cplusplus) && (!defined(HAVE_CXX11) || defined(__MINGW32__))
32 # ifndef __STDC_FORMAT_MACROS
33 # define __STDC_FORMAT_MACROS 1
34 # endif
35 # ifndef __STDC_CONSTANT_MACROS
36 # define __STDC_CONSTANT_MACROS 1
37 # endif
38 # ifndef __STDC_LIMIT_MACROS
39 # define __STDC_LIMIT_MACROS 1
40 # endif
41 #endif
43 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R) \
44 || !defined (HAVE_TIMEGM)
45 # include <time.h> /* time_t */
46 #endif
48 #ifndef HAVE_LLDIV
49 typedef struct
51 long long quot; /* Quotient. */
52 long long rem; /* Remainder. */
53 } lldiv_t;
54 #endif
56 #if !defined(HAVE_GETENV) || \
57 !defined(HAVE_USELOCALE)
58 # include <stddef.h> /* NULL */
59 #endif
61 #if !defined (HAVE_REWIND) || \
62 !defined (HAVE_GETDELIM)
63 # include <stdio.h> /* FILE */
64 #endif
66 #if !defined (HAVE_POSIX_MEMALIGN) || \
67 !defined (HAVE_STRLCPY) || \
68 !defined (HAVE_STRNDUP) || \
69 !defined (HAVE_STRNLEN)
70 # include <stddef.h> /* size_t */
71 #endif
73 #ifndef HAVE_VASPRINTF
74 # include <stdarg.h> /* va_list */
75 #endif
77 #if !defined (HAVE_GETDELIM) || \
78 !defined (HAVE_GETPID) || \
79 !defined (HAVE_SWAB)
80 # include <sys/types.h> /* ssize_t, pid_t */
81 #endif
83 #if !defined (HAVE_DIRFD) || \
84 !defined (HAVE_FDOPENDIR)
85 # include <dirent.h>
86 #endif
88 #ifdef __cplusplus
89 # define VLC_NOTHROW throw ()
90 extern "C" {
91 #else
92 # define VLC_NOTHROW
93 #endif
95 /* stdio.h */
96 #ifndef HAVE_ASPRINTF
97 int asprintf (char **, const char *, ...);
98 #endif
100 #ifndef HAVE_FLOCKFILE
101 void flockfile (FILE *);
102 int ftrylockfile (FILE *);
103 void funlockfile (FILE *);
104 int getc_unlocked (FILE *);
105 int getchar_unlocked (void);
106 int putc_unlocked (int, FILE *);
107 int putchar_unlocked (int);
108 #endif
110 #ifndef HAVE_GETDELIM
111 ssize_t getdelim (char **, size_t *, int, FILE *);
112 ssize_t getline (char **, size_t *, FILE *);
113 #endif
115 #ifndef HAVE_REWIND
116 void rewind (FILE *);
117 #endif
119 #ifndef HAVE_VASPRINTF
120 int vasprintf (char **, const char *, va_list);
121 #endif
123 /* string.h */
124 #ifndef HAVE_FFSLL
125 int ffsll(unsigned long long);
126 #endif
128 #ifndef HAVE_STRCASECMP
129 int strcasecmp (const char *, const char *);
130 #endif
132 #ifndef HAVE_STRCASESTR
133 char *strcasestr (const char *, const char *);
134 #endif
136 #ifndef HAVE_STRDUP
137 char *strdup (const char *);
138 #endif
140 #ifndef HAVE_STRVERSCMP
141 int strverscmp (const char *, const char *);
142 #endif
144 #ifndef HAVE_STRNLEN
145 size_t strnlen (const char *, size_t);
146 #endif
148 #ifndef HAVE_STRNSTR
149 char * strnstr (const char *, const char *, size_t);
150 #endif
152 #ifndef HAVE_STRNDUP
153 char *strndup (const char *, size_t);
154 #endif
156 #ifndef HAVE_STRLCPY
157 size_t strlcpy (char *, const char *, size_t);
158 #endif
160 #ifndef HAVE_STRSEP
161 char *strsep (char **, const char *);
162 #endif
164 #ifndef HAVE_STRTOK_R
165 char *strtok_r(char *, const char *, char **);
166 #endif
168 /* stdlib.h */
169 #ifndef HAVE_ATOF
170 #ifndef __ANDROID__
171 double atof (const char *);
172 #endif
173 #endif
175 #ifndef HAVE_ATOLL
176 long long atoll (const char *);
177 #endif
179 #ifndef HAVE_LLDIV
180 lldiv_t lldiv (long long, long long);
181 #endif
183 #ifndef HAVE_STRTOF
184 #ifndef __ANDROID__
185 float strtof (const char *, char **);
186 #endif
187 #endif
189 #ifndef HAVE_STRTOLL
190 long long int strtoll (const char *, char **, int);
191 #endif
193 /* time.h */
194 #ifndef HAVE_GMTIME_R
195 struct tm *gmtime_r (const time_t *, struct tm *);
196 #endif
198 #ifndef HAVE_LOCALTIME_R
199 struct tm *localtime_r (const time_t *, struct tm *);
200 #endif
202 #ifndef HAVE_TIMEGM
203 time_t timegm(struct tm *);
204 #endif
206 #ifndef HAVE_TIMESPEC_GET
207 #define TIME_UTC 1
208 struct timespec;
209 int timespec_get(struct timespec *, int);
210 #endif
212 /* unistd.h */
213 #ifndef HAVE_GETPID
214 pid_t getpid (void) VLC_NOTHROW;
215 #endif
217 #ifndef HAVE_FSYNC
218 int fsync (int fd);
219 #endif
221 /* dirent.h */
222 #ifndef HAVE_DIRFD
223 int (dirfd) (DIR *);
224 #endif
226 #ifndef HAVE_FDOPENDIR
227 DIR *fdopendir (int);
228 #endif
230 #ifdef __cplusplus
231 } /* extern "C" */
232 #endif
234 /* stdlib.h */
235 #ifndef HAVE_GETENV
236 static inline char *getenv (const char *name)
238 (void)name;
239 return NULL;
241 #endif
243 #ifndef HAVE_SETENV
244 int setenv (const char *, const char *, int);
245 int unsetenv (const char *);
246 #endif
248 #ifndef HAVE_POSIX_MEMALIGN
249 int posix_memalign (void **, size_t, size_t);
250 #endif
252 /* locale.h */
253 #ifndef HAVE_USELOCALE
254 #define LC_ALL_MASK 0
255 #define LC_NUMERIC_MASK 0
256 #define LC_MESSAGES_MASK 0
257 #define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
258 typedef void *locale_t;
259 static inline locale_t uselocale(locale_t loc)
261 (void)loc;
262 return NULL;
264 static inline void freelocale(locale_t loc)
266 (void)loc;
268 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
270 (void)mask; (void)locale; (void)base;
271 return NULL;
273 #endif
275 #if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
276 # define _Static_assert(x, s) ((void) sizeof (struct { unsigned:-!(x); }))
277 # define static_assert _Static_assert
278 #endif
280 /* Alignment of critical static data structures */
281 #ifdef ATTRIBUTE_ALIGNED_MAX
282 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
283 #else
284 # define ATTR_ALIGN(align)
285 #endif
287 /* libintl support */
288 #define _(str) vlc_gettext (str)
289 #define N_(str) gettext_noop (str)
290 #define gettext_noop(str) (str)
292 #ifdef __cplusplus
293 extern "C" {
294 #endif
296 #ifndef HAVE_SWAB
297 void swab (const void *, void *, ssize_t);
298 #endif
300 /* Socket stuff */
301 #ifndef HAVE_INET_PTON
302 int inet_pton(int, const char *, void *);
303 const char *inet_ntop(int, const void *, char *, int);
304 #endif
306 #ifndef HAVE_STRUCT_POLLFD
307 enum
309 POLLERR=0x1,
310 POLLHUP=0x2,
311 POLLNVAL=0x4,
312 POLLWRNORM=0x10,
313 POLLWRBAND=0x20,
314 POLLRDNORM=0x100,
315 POLLRDBAND=0x200,
316 POLLPRI=0x400,
318 #define POLLIN (POLLRDNORM|POLLRDBAND)
319 #define POLLOUT (POLLWRNORM|POLLWRBAND)
321 struct pollfd
323 int fd;
324 unsigned events;
325 unsigned revents;
327 #endif
328 #ifndef HAVE_POLL
329 struct pollfd;
330 int poll (struct pollfd *, unsigned, int);
331 #endif
333 #ifndef HAVE_IF_NAMEINDEX
334 #include <errno.h>
335 struct if_nameindex
337 unsigned if_index;
338 char *if_name;
340 # ifndef HAVE_IF_NAMETOINDEX
341 # define if_nametoindex(name) atoi(name)
342 # endif
343 # define if_nameindex() (errno = ENOBUFS, NULL)
344 # define if_freenameindex(list) (void)0
345 #endif
347 /* search.h */
348 #ifndef HAVE_SEARCH_H
349 typedef struct entry {
350 char *key;
351 void *data;
352 } ENTRY;
354 typedef enum {
355 FIND, ENTER
356 } ACTION;
358 typedef enum {
359 preorder,
360 postorder,
361 endorder,
362 leaf
363 } VISIT;
365 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
366 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
367 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
368 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
369 void tdestroy( void *root, void (*free_node)(void *nodep) );
370 #else // HAVE_SEARCH_H
371 # ifndef HAVE_TDESTROY
372 # define tdestroy vlc_tdestroy
373 # endif
374 #endif
376 /* Random numbers */
377 #ifndef HAVE_NRAND48
378 double erand48 (unsigned short subi[3]);
379 long jrand48 (unsigned short subi[3]);
380 long nrand48 (unsigned short subi[3]);
381 #endif
383 #ifdef __OS2__
384 # undef HAVE_FORK /* Implementation of fork() is imperfect on OS/2 */
386 struct addrinfo
388 int ai_flags;
389 int ai_family;
390 int ai_socktype;
391 int ai_protocol;
392 size_t ai_addrlen;
393 struct sockaddr *ai_addr;
394 char *ai_canonname;
395 struct addrinfo *ai_next;
398 void freeaddrinfo (struct addrinfo *res);
399 #endif
401 /* math.h */
403 #ifndef HAVE_NANF
404 #define nanf(tagp) NAN
405 #endif
407 #ifdef _WIN32
408 FILE *vlc_win32_tmpfile(void);
409 #endif
411 #ifdef __cplusplus
412 } /* extern "C" */
413 #endif
415 #endif /* !LIBVLC_FIXUPS_H */