]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
compat: mark getpid() as not throwing exceptions in C++
[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_POSIX_MEMALIGN) || \
52     !defined (HAVE_STRLCPY) || \
53     !defined (HAVE_STRNDUP) || \
54     !defined (HAVE_STRNLEN)
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 #if !defined (HAVE_DIRFD) || \
69     !defined (HAVE_FDOPENDIR)
70 # include <dirent.h>
71 #endif
72
73 #ifdef __cplusplus
74 # define VLC_NOTHROW throw ()
75 extern "C" {
76 #else
77 # define VLC_NOTHROW
78 #endif
79
80 /* stdio.h */
81 #ifndef HAVE_ASPRINTF
82 int asprintf (char **, const char *, ...);
83 #endif
84
85 #ifndef HAVE_FLOCKFILE
86 void flockfile (FILE *);
87 int ftrylockfile (FILE *);
88 void funlockfile (FILE *);
89 int getc_unlocked (FILE *);
90 int getchar_unlocked (void);
91 int putc_unlocked (int, FILE *);
92 int putchar_unlocked (int);
93 #endif
94
95 #ifndef HAVE_GETDELIM
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_STRVERSCMP
126 int strverscmp (const char *, const char *);
127 #endif
128
129 #ifndef HAVE_STRNLEN
130 size_t strnlen (const char *, size_t);
131 #endif
132
133 #ifndef HAVE_STRNDUP
134 char *strndup (const char *, size_t);
135 #endif
136
137 #ifndef HAVE_STRLCPY
138 size_t strlcpy (char *, const char *, size_t);
139 #endif
140
141 #ifndef HAVE_STRSEP
142 char *strsep (char **, const char *);
143 #endif
144
145 #ifndef HAVE_STRTOK_R
146 char *strtok_r(char *, const char *, char **);
147 #endif
148
149 /* stdlib.h */
150 #ifndef HAVE_ATOF
151 #ifndef __ANDROID__
152 double atof (const char *);
153 #endif
154 #endif
155
156 #ifndef HAVE_ATOLL
157 long long atoll (const char *);
158 #endif
159
160 #ifndef HAVE_LLDIV
161 lldiv_t lldiv (long long, long long);
162 #endif
163
164 #ifndef HAVE_STRTOF
165 #ifndef __ANDROID__
166 float strtof (const char *, char **);
167 #endif
168 #endif
169
170 #ifndef HAVE_STRTOLL
171 long long int strtoll (const char *, char **, int);
172 #endif
173
174 /* time.h */
175 #ifndef HAVE_GMTIME_R
176 struct tm *gmtime_r (const time_t *, struct tm *);
177 #endif
178
179 #ifndef HAVE_LOCALTIME_R
180 struct tm *localtime_r (const time_t *, struct tm *);
181 #endif
182
183 /* unistd.h */
184 #ifndef HAVE_GETPID
185 pid_t getpid (void) VLC_NOTHROW;
186 #endif
187
188 #ifndef HAVE_FSYNC
189 int fsync (int fd);
190 #endif
191
192 /* dirent.h */
193 #ifndef HAVE_DIRFD
194 int (dirfd) (DIR *);
195 #endif
196
197 #ifndef HAVE_FDOPENDIR
198 DIR *fdopendir (int);
199 #endif
200
201 #ifdef __cplusplus
202 } /* extern "C" */
203 #endif
204
205 /* stdlib.h */
206 #ifndef HAVE_GETENV
207 static inline char *getenv (const char *name)
208 {
209     (void)name;
210     return NULL;
211 }
212 #endif
213
214 #ifndef HAVE_SETENV
215 int setenv (const char *, const char *, int);
216 int unsetenv (const char *);
217 #endif
218
219 #ifndef HAVE_POSIX_MEMALIGN
220 int posix_memalign (void **, size_t, size_t);
221 #endif
222
223 /* locale.h */
224 #ifndef HAVE_USELOCALE
225 #define LC_NUMERIC_MASK  0
226 #define LC_MESSAGES_MASK 0
227 typedef void *locale_t;
228 static inline locale_t uselocale(locale_t loc)
229 {
230     (void)loc;
231     return NULL;
232 }
233 static inline void freelocale(locale_t loc)
234 {
235     (void)loc;
236 }
237 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
238 {
239     (void)mask; (void)locale; (void)base;
240     return NULL;
241 }
242 #endif
243
244 #if !defined (HAVE_STATIC_ASSERT)
245 # define _Static_assert(x, s) ((void) sizeof (struct { unsigned:-!(x); }))
246 # define static_assert _Static_assert
247 #endif
248
249 /* Alignment of critical static data structures */
250 #ifdef ATTRIBUTE_ALIGNED_MAX
251 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
252 #else
253 #   define ATTR_ALIGN(align)
254 #endif
255
256 /* libintl support */
257 #define _(str)            vlc_gettext (str)
258 #define N_(str)           gettext_noop (str)
259 #define gettext_noop(str) (str)
260
261 #ifndef HAVE_SWAB
262 void swab (const void *, void *, ssize_t);
263 #endif
264
265 /* Socket stuff */
266 #ifndef HAVE_INET_PTON
267 int inet_pton(int, const char *, void *);
268 const char *inet_ntop(int, const void *, char *, int);
269 #endif
270
271 #ifndef HAVE_STRUCT_POLLFD
272 enum
273 {
274     POLLIN=1,
275     POLLOUT=2,
276     POLLPRI=4,
277     POLLERR=8,  // unsupported stub
278     POLLHUP=16, // unsupported stub
279     POLLNVAL=32 // unsupported stub
280 };
281
282 struct pollfd
283 {
284     int fd;
285     unsigned events;
286     unsigned revents;
287 };
288 #endif
289 #ifndef HAVE_POLL
290 struct pollfd;
291 int poll (struct pollfd *, unsigned, int);
292 #endif
293
294 #ifndef HAVE_IF_NAMEINDEX
295 #include <errno.h>
296 struct if_nameindex
297 {
298     unsigned if_index;
299     char    *if_name;
300 };
301 # ifndef HAVE_IF_NAMETOINDEX
302 #  define if_nametoindex(name)   atoi(name)
303 # endif
304 # define if_nameindex()         (errno = ENOBUFS, NULL)
305 # define if_freenameindex(list) (void)0
306 #endif
307
308 /* search.h */
309 #ifndef HAVE_SEARCH_H
310 typedef struct entry {
311     char *key;
312     void *data;
313 } ENTRY;
314
315 typedef enum {
316     FIND, ENTER
317 } ACTION;
318
319 typedef enum {
320     preorder,
321     postorder,
322     endorder,
323     leaf
324 } VISIT;
325
326 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
327 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
328 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
329 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
330 void tdestroy( void *root, void (*free_node)(void *nodep) );
331 #else // HAVE_SEARCH_H
332 # ifndef HAVE_TDESTROY
333 #  define tdestroy vlc_tdestroy
334 # endif
335 #endif
336
337 /* Random numbers */
338 #ifndef HAVE_NRAND48
339 double erand48 (unsigned short subi[3]);
340 long jrand48 (unsigned short subi[3]);
341 long nrand48 (unsigned short subi[3]);
342 #endif
343
344 #ifdef __OS2__
345 # undef HAVE_FORK   /* Implementation of fork() is imperfect on OS/2 */
346 #endif
347
348 #endif /* !LIBVLC_FIXUPS_H */