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