]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
Undefine HAVE_FORK on OS/2.
[vlc] / include / vlc_fixups.h
1 /*****************************************************************************
2  * 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
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 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 General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, 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     !defined (HAVE_GETCWD)
55 # include <stddef.h> /* size_t */
56 #endif
57
58 #ifndef HAVE_VASPRINTF
59 # include <stdarg.h> /* va_list */
60 #endif
61
62 #if !defined (HAVE_GETDELIM) || \
63     !defined (HAVE_GETPID)   || \
64     !defined (HAVE_SWAB)
65 # include <sys/types.h> /* ssize_t, pid_t */
66 #endif
67
68 #ifndef HAVE_DIRFD
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_GETDELIM
82 ssize_t getdelim (char **, size_t *, int, FILE *);
83 ssize_t getline (char **, size_t *, FILE *);
84 #endif
85
86 #ifndef HAVE_REWIND
87 void rewind (FILE *);
88 #endif
89
90 #ifndef HAVE_VASPRINTF
91 int vasprintf (char **, const char *, va_list);
92 #endif
93
94 /* string.h */
95 #ifndef HAVE_STRCASECMP
96 int strcasecmp (const char *, const char *);
97 #endif
98
99 #ifndef HAVE_STRCASESTR
100 char *strcasestr (const char *, const char *);
101 #endif
102
103 #ifndef HAVE_STRDUP
104 char *strdup (const char *);
105 #endif
106
107 #ifndef HAVE_STRNCASECMP
108 int strncasecmp (const char *, const char *, size_t);
109 #endif
110
111 #ifndef HAVE_STRNLEN
112 size_t strnlen (const char *, size_t);
113 #endif
114
115 #ifndef HAVE_STRNDUP
116 char *strndup (const char *, size_t);
117 #endif
118
119 #ifndef HAVE_STRLCPY
120 size_t strlcpy (char *, const char *, size_t);
121 #endif
122
123 #ifndef HAVE_STRSEP
124 char *strsep (char **, const char *);
125 #endif
126
127 #ifndef HAVE_STRTOK_R
128 char *strtok_r(char *, const char *, char **);
129 #endif
130
131 /* stdlib.h */
132 #ifndef HAVE_ATOF
133 #ifndef __ANDROID__
134 double atof (const char *);
135 #endif
136 #endif
137
138 #ifndef HAVE_ATOLL
139 long long atoll (const char *);
140 #endif
141
142 #ifndef HAVE_LLDIV
143 lldiv_t lldiv (long long, long long);
144 #endif
145
146 #ifndef HAVE_STRTOF
147 #ifndef __ANDROID__
148 float strtof (const char *, char **);
149 #endif
150 #endif
151
152 #ifndef HAVE_STRTOLL
153 long long int strtoll (const char *, char **, int);
154 #endif
155
156 /* time.h */
157 #ifndef HAVE_GMTIME_R
158 struct tm *gmtime_r (const time_t *, struct tm *);
159 #endif
160
161 #ifndef HAVE_LOCALTIME_R
162 struct tm *localtime_r (const time_t *, struct tm *);
163 #endif
164
165 /* unistd.h */
166 #ifndef HAVE_GETCWD
167 char *getcwd (char *buf, size_t size);
168 #endif
169
170 #ifndef HAVE_GETPID
171 pid_t getpid (void);
172 #endif
173
174 /* dirent.h */
175 #ifndef HAVE_DIRFD
176 #ifdef __APPLE__
177 #undef dirfd
178 #endif
179 int dirfd (DIR *);
180 #endif
181
182 #ifdef __cplusplus
183 } /* extern "C" */
184 #endif
185
186 /* stdlib.h */
187 #ifndef HAVE_GETENV
188 static inline char *getenv (const char *name)
189 {
190     (void)name;
191     return NULL;
192 }
193 #endif
194
195 #ifndef HAVE_SETENV
196 int setenv (const char *, const char *, int);
197 int unsetenv (const char *);
198 #endif
199
200 /* locale.h */
201 #ifndef HAVE_USELOCALE
202 #define LC_NUMERIC_MASK  0
203 #define LC_MESSAGES_MASK 0
204 typedef void *locale_t;
205 static inline locale_t uselocale(locale_t loc)
206 {
207     (void)loc;
208     return NULL;
209 }
210 static inline void freelocale(locale_t loc)
211 {
212     (void)loc;
213 }
214 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
215 {
216     (void)mask; (void)locale; (void)base;
217     return NULL;
218 }
219 #endif
220
221 /* Alignment of critical static data structures */
222 #ifdef ATTRIBUTE_ALIGNED_MAX
223 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
224 #else
225 #   define ATTR_ALIGN(align)
226 #endif
227
228 /* libintl support */
229 #define _(str)            vlc_gettext (str)
230 #define N_(str)           gettext_noop (str)
231 #define gettext_noop(str) (str)
232
233 #ifndef HAVE_SWAB
234 void swab (const void *, void *, ssize_t);
235 #endif
236
237 /* Socket stuff */
238 #ifndef HAVE_INET_PTON
239 # define inet_pton vlc_inet_pton
240 #endif
241
242 #ifndef HAVE_INET_NTOP
243 # define inet_ntop vlc_inet_ntop
244 #endif
245
246 #ifndef HAVE_POLL
247 enum
248 {
249     POLLIN=1,
250     POLLOUT=2,
251     POLLPRI=4,
252     POLLERR=8,  // unsupported stub
253     POLLHUP=16, // unsupported stub
254     POLLNVAL=32 // unsupported stub
255 };
256
257 struct pollfd
258 {
259     int fd;
260     unsigned events;
261     unsigned revents;
262 };
263
264 # define poll(a, b, c) vlc_poll(a, b, c)
265 #elif defined (HAVE_MAEMO)
266 # include <poll.h>
267 # define poll(a, b, c) vlc_poll(a, b, c)
268 int vlc_poll (struct pollfd *, unsigned, int);
269 #endif
270
271 /* search.h */
272 #ifndef HAVE_SEARCH_H
273 typedef struct entry {
274     char *key;
275     void *data;
276 } ENTRY;
277
278 typedef enum {
279     FIND, ENTER
280 } ACTION;
281
282 typedef enum {
283     preorder,
284     postorder,
285     endorder,
286     leaf
287 } VISIT;
288
289 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
290 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
291 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
292 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
293 void tdestroy( void *root, void (*free_node)(void *nodep) );
294 #else // HAVE_SEARCH_H
295 # ifndef HAVE_TDESTROY
296 #  define tdestroy vlc_tdestroy
297 # endif
298 #endif
299
300 /* Random numbers */
301 #ifndef HAVE_NRAND48
302 double erand48 (unsigned short subi[3]);
303 long jrand48 (unsigned short subi[3]);
304 long nrand48 (unsigned short subi[3]);
305 #endif
306
307 #ifdef __ANDROID__
308 # undef __linux__
309 # ifndef __cplusplus
310 #  define __cplusplus 0
311 # endif
312 # include <pthread.h>
313 # if __cplusplus == 0
314 #  undef __cplusplus
315 # endif
316 char *tempnam(const char *, const char *);
317 #endif // ANDROID
318
319 #ifdef __OS2__
320 # undef HAVE_FORK   /* Implementation of fork() is imperfect on OS/2 */
321 #endif
322
323 #endif /* !LIBVLC_FIXUPS_H */