]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
Win32: fsync() replacement
[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_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 #ifndef HAVE_GETDELIM
92 ssize_t getdelim (char **, size_t *, int, FILE *);
93 ssize_t getline (char **, size_t *, FILE *);
94 #endif
95
96 #ifndef HAVE_REWIND
97 void rewind (FILE *);
98 #endif
99
100 #ifndef HAVE_VASPRINTF
101 int vasprintf (char **, const char *, va_list);
102 #endif
103
104 /* string.h */
105 #ifndef HAVE_STRCASECMP
106 int strcasecmp (const char *, const char *);
107 #endif
108
109 #ifndef HAVE_STRCASESTR
110 char *strcasestr (const char *, const char *);
111 #endif
112
113 #ifndef HAVE_STRDUP
114 char *strdup (const char *);
115 #endif
116
117 #ifndef HAVE_STRNCASECMP
118 int strncasecmp (const char *, const char *, size_t);
119 #endif
120
121 #ifndef HAVE_STRNLEN
122 size_t strnlen (const char *, size_t);
123 #endif
124
125 #ifndef HAVE_STRNDUP
126 char *strndup (const char *, size_t);
127 #endif
128
129 #ifndef HAVE_STRLCPY
130 size_t strlcpy (char *, const char *, size_t);
131 #endif
132
133 #ifndef HAVE_STRSEP
134 char *strsep (char **, const char *);
135 #endif
136
137 #ifndef HAVE_STRTOK_R
138 char *strtok_r(char *, const char *, char **);
139 #endif
140
141 /* stdlib.h */
142 #ifndef HAVE_ATOF
143 #ifndef __ANDROID__
144 double atof (const char *);
145 #endif
146 #endif
147
148 #ifndef HAVE_ATOLL
149 long long atoll (const char *);
150 #endif
151
152 #ifndef HAVE_LLDIV
153 lldiv_t lldiv (long long, long long);
154 #endif
155
156 #ifndef HAVE_STRTOF
157 #ifndef __ANDROID__
158 float strtof (const char *, char **);
159 #endif
160 #endif
161
162 #ifndef HAVE_STRTOLL
163 long long int strtoll (const char *, char **, int);
164 #endif
165
166 /* time.h */
167 #ifndef HAVE_GMTIME_R
168 struct tm *gmtime_r (const time_t *, struct tm *);
169 #endif
170
171 #ifndef HAVE_LOCALTIME_R
172 struct tm *localtime_r (const time_t *, struct tm *);
173 #endif
174
175 /* unistd.h */
176 #ifndef HAVE_GETCWD
177 char *getcwd (char *buf, size_t size);
178 #endif
179
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 #ifdef __APPLE__
191 #undef dirfd
192 #endif
193 int dirfd (DIR *);
194 #endif
195
196 #ifdef __cplusplus
197 } /* extern "C" */
198 #endif
199
200 /* stdlib.h */
201 #ifndef HAVE_GETENV
202 static inline char *getenv (const char *name)
203 {
204     (void)name;
205     return NULL;
206 }
207 #endif
208
209 #ifndef HAVE_SETENV
210 int setenv (const char *, const char *, int);
211 int unsetenv (const char *);
212 #endif
213
214 /* locale.h */
215 #ifndef HAVE_USELOCALE
216 #define LC_NUMERIC_MASK  0
217 #define LC_MESSAGES_MASK 0
218 typedef void *locale_t;
219 static inline locale_t uselocale(locale_t loc)
220 {
221     (void)loc;
222     return NULL;
223 }
224 static inline void freelocale(locale_t loc)
225 {
226     (void)loc;
227 }
228 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
229 {
230     (void)mask; (void)locale; (void)base;
231     return NULL;
232 }
233 #endif
234
235 /* Alignment of critical static data structures */
236 #ifdef ATTRIBUTE_ALIGNED_MAX
237 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
238 #else
239 #   define ATTR_ALIGN(align)
240 #endif
241
242 /* libintl support */
243 #define _(str)            vlc_gettext (str)
244 #define N_(str)           gettext_noop (str)
245 #define gettext_noop(str) (str)
246
247 #ifndef HAVE_SWAB
248 void swab (const void *, void *, ssize_t);
249 #endif
250
251 /* Socket stuff */
252 #ifndef HAVE_INET_PTON
253 # define inet_pton vlc_inet_pton
254 #endif
255
256 #ifndef HAVE_INET_NTOP
257 # define inet_ntop vlc_inet_ntop
258 #endif
259
260 #ifndef HAVE_POLL
261 enum
262 {
263     POLLIN=1,
264     POLLOUT=2,
265     POLLPRI=4,
266     POLLERR=8,  // unsupported stub
267     POLLHUP=16, // unsupported stub
268     POLLNVAL=32 // unsupported stub
269 };
270
271 struct pollfd
272 {
273     int fd;
274     unsigned events;
275     unsigned revents;
276 };
277
278 # define poll(a, b, c) vlc_poll(a, b, c)
279 #elif defined (HAVE_MAEMO)
280 # include <poll.h>
281 # define poll(a, b, c) vlc_poll(a, b, c)
282 int vlc_poll (struct pollfd *, unsigned, int);
283 #endif
284
285 #ifndef HAVE_IF_NAMEINDEX
286 #include <errno.h>
287 struct if_nameindex
288 {
289     unsigned if_index;
290     char    *if_name;
291 };
292 # ifndef HAVE_IF_NAMETOINDEX
293 #  define if_nametoindex(name)   atoi(name)
294 # endif
295 # define if_nameindex()         (errno = ENOBUFS, NULL)
296 # define if_freenameindex(list) (void)0
297 #endif
298
299 /* search.h */
300 #ifndef HAVE_SEARCH_H
301 typedef struct entry {
302     char *key;
303     void *data;
304 } ENTRY;
305
306 typedef enum {
307     FIND, ENTER
308 } ACTION;
309
310 typedef enum {
311     preorder,
312     postorder,
313     endorder,
314     leaf
315 } VISIT;
316
317 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
318 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
319 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
320 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
321 void tdestroy( void *root, void (*free_node)(void *nodep) );
322 #else // HAVE_SEARCH_H
323 # ifndef HAVE_TDESTROY
324 #  define tdestroy vlc_tdestroy
325 # endif
326 #endif
327
328 /* Random numbers */
329 #ifndef HAVE_NRAND48
330 double erand48 (unsigned short subi[3]);
331 long jrand48 (unsigned short subi[3]);
332 long nrand48 (unsigned short subi[3]);
333 #endif
334
335 #ifdef __ANDROID__
336 # undef __linux__
337 # ifndef __cplusplus
338 #  define __cplusplus 0
339 # endif
340 # include <pthread.h>
341 # if __cplusplus == 0
342 #  undef __cplusplus
343 # endif
344 char *tempnam(const char *, const char *);
345 #endif // ANDROID
346
347 #ifdef __OS2__
348 # undef HAVE_FORK   /* Implementation of fork() is imperfect on OS/2 */
349 #endif
350
351 #endif /* !LIBVLC_FIXUPS_H */