]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
fixups.h: added an explicit hack so binaries created on OS X Lion can be executed...
[vlc] / include / vlc_fixups.h
1 /*****************************************************************************
2  * vlc_fixups.h: portability fixups included from config.h
3  *****************************************************************************
4  * Copyright © 1998-2008 the VideoLAN project
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 /**
22  * \file
23  * This file is a collection of portability fixes
24  */
25
26 #ifndef LIBVLC_FIXUPS_H
27 # define LIBVLC_FIXUPS_H 1
28
29 #if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R)
30 # include <time.h> /* time_t */
31 #endif
32
33 #ifndef HAVE_LLDIV
34 typedef struct
35 {
36     long long quot; /* Quotient. */
37     long long rem;  /* Remainder. */
38 } lldiv_t;
39 #endif
40
41 #if !defined(HAVE_GETENV) || \
42     !defined(HAVE_USELOCALE)
43 # include <stddef.h> /* NULL */
44 #endif
45
46 #if !defined (HAVE_REWIND) || \
47     !defined (HAVE_GETDELIM)
48 # include <stdio.h> /* FILE */
49 #endif
50
51 #if !defined (HAVE_STRLCPY) || \
52     !defined (HAVE_STRNDUP) || \
53     !defined (HAVE_STRNLEN)
54 # include <stddef.h> /* size_t */
55 #endif
56
57 #ifndef HAVE_VASPRINTF
58 # include <stdarg.h> /* va_list */
59 #endif
60
61 #if !defined (HAVE_GETDELIM) || \
62     !defined (HAVE_GETPID)   || \
63     !defined (HAVE_SWAB)
64 # include <sys/types.h> /* ssize_t, pid_t */
65 #endif
66
67 #if !defined (HAVE_DIRFD) || \
68     !defined (HAVE_FDOPENDIR)
69 # include <dirent.h>
70 #endif
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 /* stdio.h */
77 #ifndef HAVE_ASPRINTF
78 int asprintf (char **, const char *, ...);
79 #endif
80
81 #ifndef HAVE_FLOCKFILE
82 void flockfile (FILE *);
83 int ftrylockfile (FILE *);
84 void funlockfile (FILE *);
85 int getc_unlocked (FILE *);
86 int getchar_unlocked (void);
87 int putc_unlocked (int, FILE *);
88 int putchar_unlocked (int);
89 #endif
90
91 /* we always need our implementation on Darwin, since native support for getline
92  * was added lately to Darwin 11 (OS X Lion) only.
93  * However, we want binaries created on this OS to be executable on previous
94  * releases. */
95 #if !defined HAVE_GETDELIM || defined(__APPLE__)
96 ssize_t getdelim (char **, size_t *, int, FILE *);
97 ssize_t getline (char **, size_t *, FILE *);
98 #endif
99
100 #ifndef HAVE_REWIND
101 void rewind (FILE *);
102 #endif
103
104 #ifndef HAVE_VASPRINTF
105 int vasprintf (char **, const char *, va_list);
106 #endif
107
108 /* string.h */
109 #ifndef HAVE_STRCASECMP
110 int strcasecmp (const char *, const char *);
111 #endif
112
113 #ifndef HAVE_STRCASESTR
114 char *strcasestr (const char *, const char *);
115 #endif
116
117 #ifndef HAVE_STRDUP
118 char *strdup (const char *);
119 #endif
120
121 #ifndef HAVE_STRNCASECMP
122 int strncasecmp (const char *, const char *, size_t);
123 #endif
124
125 #ifndef HAVE_STRNLEN
126 size_t strnlen (const char *, size_t);
127 #endif
128
129 #ifndef HAVE_STRNDUP
130 char *strndup (const char *, size_t);
131 #endif
132
133 #ifndef HAVE_STRLCPY
134 size_t strlcpy (char *, const char *, size_t);
135 #endif
136
137 #ifndef HAVE_STRSEP
138 char *strsep (char **, const char *);
139 #endif
140
141 #ifndef HAVE_STRTOK_R
142 char *strtok_r(char *, const char *, char **);
143 #endif
144
145 /* stdlib.h */
146 #ifndef HAVE_ATOF
147 #ifndef __ANDROID__
148 double atof (const char *);
149 #endif
150 #endif
151
152 #ifndef HAVE_ATOLL
153 long long atoll (const char *);
154 #endif
155
156 #ifndef HAVE_LLDIV
157 lldiv_t lldiv (long long, long long);
158 #endif
159
160 #ifndef HAVE_STRTOF
161 #ifndef __ANDROID__
162 float strtof (const char *, char **);
163 #endif
164 #endif
165
166 #ifndef HAVE_STRTOLL
167 long long int strtoll (const char *, char **, int);
168 #endif
169
170 /* time.h */
171 #ifndef HAVE_GMTIME_R
172 struct tm *gmtime_r (const time_t *, struct tm *);
173 #endif
174
175 #ifndef HAVE_LOCALTIME_R
176 struct tm *localtime_r (const time_t *, struct tm *);
177 #endif
178
179 /* unistd.h */
180 #ifndef HAVE_GETPID
181 pid_t getpid (void);
182 #endif
183
184 #ifndef HAVE_FSYNC
185 int fsync (int fd);
186 #endif
187
188 /* dirent.h */
189 #ifndef HAVE_DIRFD
190 int (dirfd) (DIR *);
191 #endif
192
193 #ifndef HAVE_FDOPENDIR
194 DIR *fdopendir (int);
195 #endif
196
197 #ifdef __cplusplus
198 } /* extern "C" */
199 #endif
200
201 /* stdlib.h */
202 #ifndef HAVE_GETENV
203 static inline char *getenv (const char *name)
204 {
205     (void)name;
206     return NULL;
207 }
208 #endif
209
210 #ifndef HAVE_SETENV
211 int setenv (const char *, const char *, int);
212 int unsetenv (const char *);
213 #endif
214
215 /* locale.h */
216 #ifndef HAVE_USELOCALE
217 #define LC_NUMERIC_MASK  0
218 #define LC_MESSAGES_MASK 0
219 typedef void *locale_t;
220 static inline locale_t uselocale(locale_t loc)
221 {
222     (void)loc;
223     return NULL;
224 }
225 static inline void freelocale(locale_t loc)
226 {
227     (void)loc;
228 }
229 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
230 {
231     (void)mask; (void)locale; (void)base;
232     return NULL;
233 }
234 #endif
235
236 /* Alignment of critical static data structures */
237 #ifdef ATTRIBUTE_ALIGNED_MAX
238 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
239 #else
240 #   define ATTR_ALIGN(align)
241 #endif
242
243 /* libintl support */
244 #define _(str)            vlc_gettext (str)
245 #define N_(str)           gettext_noop (str)
246 #define gettext_noop(str) (str)
247
248 #ifndef HAVE_SWAB
249 void swab (const void *, void *, ssize_t);
250 #endif
251
252 /* Socket stuff */
253 #ifndef HAVE_INET_PTON
254 int inet_pton(int, const char *, void *);
255 const char *inet_ntop(int, const void *, char *, int);
256 #endif
257
258 #ifndef HAVE_STRUCT_POLLFD
259 enum
260 {
261     POLLIN=1,
262     POLLOUT=2,
263     POLLPRI=4,
264     POLLERR=8,  // unsupported stub
265     POLLHUP=16, // unsupported stub
266     POLLNVAL=32 // unsupported stub
267 };
268
269 struct pollfd
270 {
271     int fd;
272     unsigned events;
273     unsigned revents;
274 };
275 #endif
276 #ifndef HAVE_POLL
277 # define poll(a, b, c) vlc_poll(a, b, c)
278 #elif defined (HAVE_MAEMO)
279 # include <poll.h>
280 # define poll(a, b, c) vlc_poll(a, b, c)
281 #endif
282
283 #ifndef HAVE_IF_NAMEINDEX
284 #include <errno.h>
285 struct if_nameindex
286 {
287     unsigned if_index;
288     char    *if_name;
289 };
290 # ifndef HAVE_IF_NAMETOINDEX
291 #  define if_nametoindex(name)   atoi(name)
292 # endif
293 # define if_nameindex()         (errno = ENOBUFS, NULL)
294 # define if_freenameindex(list) (void)0
295 #endif
296
297 /* search.h */
298 #ifndef HAVE_SEARCH_H
299 typedef struct entry {
300     char *key;
301     void *data;
302 } ENTRY;
303
304 typedef enum {
305     FIND, ENTER
306 } ACTION;
307
308 typedef enum {
309     preorder,
310     postorder,
311     endorder,
312     leaf
313 } VISIT;
314
315 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
316 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
317 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
318 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
319 void tdestroy( void *root, void (*free_node)(void *nodep) );
320 #else // HAVE_SEARCH_H
321 # ifndef HAVE_TDESTROY
322 #  define tdestroy vlc_tdestroy
323 # endif
324 #endif
325
326 /* Random numbers */
327 #ifndef HAVE_NRAND48
328 double erand48 (unsigned short subi[3]);
329 long jrand48 (unsigned short subi[3]);
330 long nrand48 (unsigned short subi[3]);
331 #endif
332
333 #ifdef __ANDROID__
334 # undef __linux__
335 # ifndef __cplusplus
336 #  define __cplusplus 0
337 # endif
338 # include <pthread.h>
339 # if __cplusplus == 0
340 #  undef __cplusplus
341 # endif
342 char *tempnam(const char *, const char *);
343 #endif // ANDROID
344
345 #ifdef __OS2__
346 # undef HAVE_FORK   /* Implementation of fork() is imperfect on OS/2 */
347 #endif
348
349 #endif /* !LIBVLC_FIXUPS_H */