]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
fixups: sort stuff a bit
[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 int dirfd (DIR *);
177 #endif
178
179 #ifdef __cplusplus
180 } /* extern "C" */
181 #endif
182
183 /* stdlib.h */
184 #ifndef HAVE_GETENV
185 static inline char *getenv (const char *name)
186 {
187     (void)name;
188     return NULL;
189 }
190 #endif
191
192 #ifndef HAVE_SETENV
193 int setenv (const char *, const char *, int);
194 int unsetenv (const char *);
195 #endif
196
197 /* locale.h */
198 #ifndef HAVE_USELOCALE
199 #define LC_NUMERIC_MASK  0
200 #define LC_MESSAGES_MASK 0
201 typedef void *locale_t;
202 static inline locale_t uselocale(locale_t loc)
203 {
204     (void)loc;
205     return NULL;
206 }
207 static inline void freelocale(locale_t loc)
208 {
209     (void)loc;
210 }
211 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
212 {
213     (void)mask; (void)locale; (void)base;
214     return NULL;
215 }
216 #endif
217
218 /* Alignment of critical static data structures */
219 #ifdef ATTRIBUTE_ALIGNED_MAX
220 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
221 #else
222 #   define ATTR_ALIGN(align)
223 #endif
224
225 /* libintl support */
226 #define _(str)            vlc_gettext (str)
227 #define N_(str)           gettext_noop (str)
228 #define gettext_noop(str) (str)
229
230 #ifndef HAVE_SWAB
231 void swab (const void *, void *, ssize_t);
232 #endif
233
234 /* Socket stuff */
235 #ifndef HAVE_INET_PTON
236 # define inet_pton vlc_inet_pton
237 #endif
238
239 #ifndef HAVE_INET_NTOP
240 # define inet_ntop vlc_inet_ntop
241 #endif
242
243 #ifndef HAVE_POLL
244 enum
245 {
246     POLLIN=1,
247     POLLOUT=2,
248     POLLPRI=4,
249     POLLERR=8,  // unsupported stub
250     POLLHUP=16, // unsupported stub
251     POLLNVAL=32 // unsupported stub
252 };
253
254 struct pollfd
255 {
256     int fd;
257     unsigned events;
258     unsigned revents;
259 };
260
261 # define poll(a, b, c) vlc_poll(a, b, c)
262 #elif defined (HAVE_MAEMO)
263 # include <poll.h>
264 # define poll(a, b, c) vlc_poll(a, b, c)
265 int vlc_poll (struct pollfd *, unsigned, int);
266 #endif
267
268 /* search.h */
269 #ifndef HAVE_SEARCH_H
270 typedef struct entry {
271     char *key;
272     void *data;
273 } ENTRY;
274
275 typedef enum {
276     FIND, ENTER
277 } ACTION;
278
279 typedef enum {
280     preorder,
281     postorder,
282     endorder,
283     leaf
284 } VISIT;
285
286 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
287 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
288 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
289 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
290 void tdestroy( void *root, void (*free_node)(void *nodep) );
291 #else // HAVE_SEARCH_H
292 # ifndef HAVE_TDESTROY
293 #  define tdestroy vlc_tdestroy
294 # endif
295 #endif
296
297 /* Random numbers */
298 #ifndef HAVE_NRAND48
299 double erand48 (unsigned short subi[3]);
300 long jrand48 (unsigned short subi[3]);
301 long nrand48 (unsigned short subi[3]);
302 #endif
303
304 #ifdef __ANDROID__
305 # undef __linux__
306 # ifndef __cplusplus
307 #  define __cplusplus 0
308 # endif
309 # include <pthread.h>
310 # if __cplusplus == 0
311 #  undef __cplusplus
312 # endif
313 char *tempnam(const char *, const char *);
314 #endif // ANDROID
315
316 #endif /* !LIBVLC_FIXUPS_H */