]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
dirfd: 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 #ifndef HAVE_STRDUP
77 char *strdup (const char *);
78 #endif
79
80 #ifndef HAVE_VASPRINTF
81 int vasprintf (char **, const char *, va_list);
82 #endif
83
84 #ifndef HAVE_ASPRINTF
85 int asprintf (char **, const char *, ...);
86 #endif
87
88 #ifndef HAVE_STRNLEN
89 size_t strnlen (const char *, size_t);
90 #endif
91
92 #ifndef HAVE_STRNDUP
93 char *strndup (const char *, size_t);
94 #endif
95
96 #ifndef HAVE_STRLCPY
97 size_t strlcpy (char *, const char *, size_t);
98 #endif
99
100 #ifndef HAVE_STRTOF
101 #ifndef __ANDROID__
102 float strtof (const char *, char **);
103 #endif
104 #endif
105
106 #ifndef HAVE_ATOF
107 #ifndef __ANDROID__
108 double atof (const char *);
109 #endif
110 #endif
111
112 #ifndef HAVE_STRTOLL
113 long long int strtoll (const char *, char **, int);
114 #endif
115
116 #ifndef HAVE_STRSEP
117 char *strsep (char **, const char *);
118 #endif
119
120 #ifndef HAVE_ATOLL
121 long long atoll (const char *);
122 #endif
123
124 #ifndef HAVE_LLDIV
125 lldiv_t lldiv (long long, long long);
126 #endif
127
128 #ifndef HAVE_STRCASECMP
129 int strcasecmp (const char *, const char *);
130 #endif
131
132 #ifndef HAVE_STRNCASECMP
133 int strncasecmp (const char *, const char *, size_t);
134 #endif
135
136 #ifndef HAVE_STRCASESTR
137 char *strcasestr (const char *, const char *);
138 #endif
139
140 #ifndef HAVE_GMTIME_R
141 struct tm *gmtime_r (const time_t *, struct tm *);
142 #endif
143
144 #ifndef HAVE_LOCALTIME_R
145 struct tm *localtime_r (const time_t *, struct tm *);
146 #endif
147
148 #ifndef HAVE_REWIND
149 void rewind (FILE *);
150 #endif
151
152 #ifndef HAVE_GETCWD
153 char *getcwd (char *buf, size_t size);
154 #endif
155
156 #ifndef HAVE_GETDELIM
157 ssize_t getdelim (char **, size_t *, int, FILE *);
158 ssize_t getline (char **, size_t *, FILE *);
159 #endif
160
161 #ifndef HAVE_GETPID
162 pid_t getpid (void);
163 #endif
164
165 #ifndef HAVE_STRTOK_R
166 char *strtok_r(char *, const char *, char **);
167 #endif
168
169 /* dirent.h */
170 #ifndef HAVE_DIRFD
171 int dirfd (DIR *);
172 #endif
173
174 #ifdef __cplusplus
175 } /* extern "C" */
176 #endif
177
178 #ifndef HAVE_GETENV
179 static inline char *getenv (const char *name)
180 {
181     (void)name;
182     return NULL;
183 }
184 #endif
185
186 #ifndef HAVE_SETENV
187 int setenv (const char *, const char *, int);
188 int unsetenv (const char *);
189 #endif
190
191 /* Alignment of critical static data structures */
192 #ifdef ATTRIBUTE_ALIGNED_MAX
193 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
194 #else
195 #   define ATTR_ALIGN(align)
196 #endif
197
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 /* libintl support */
219 #define _(str)            vlc_gettext (str)
220 #define N_(str)           gettext_noop (str)
221 #define gettext_noop(str) (str)
222
223 #ifndef HAVE_SWAB
224 void swab (const void *, void *, ssize_t);
225 #endif
226
227 /* Socket stuff */
228 #ifndef HAVE_INET_PTON
229 # define inet_pton vlc_inet_pton
230 #endif
231
232 #ifndef HAVE_INET_NTOP
233 # define inet_ntop vlc_inet_ntop
234 #endif
235
236 #ifndef HAVE_POLL
237 enum
238 {
239     POLLIN=1,
240     POLLOUT=2,
241     POLLPRI=4,
242     POLLERR=8,  // unsupported stub
243     POLLHUP=16, // unsupported stub
244     POLLNVAL=32 // unsupported stub
245 };
246
247 struct pollfd
248 {
249     int fd;
250     unsigned events;
251     unsigned revents;
252 };
253
254 # define poll(a, b, c) vlc_poll(a, b, c)
255 #elif defined (HAVE_MAEMO)
256 # include <poll.h>
257 # define poll(a, b, c) vlc_poll(a, b, c)
258 int vlc_poll (struct pollfd *, unsigned, int);
259 #endif
260
261 #ifndef HAVE_SEARCH_H
262 typedef struct entry {
263     char *key;
264     void *data;
265 } ENTRY;
266
267 typedef enum {
268     FIND, ENTER
269 } ACTION;
270
271 typedef enum {
272     preorder,
273     postorder,
274     endorder,
275     leaf
276 } VISIT;
277
278 void *tsearch( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
279 void *tfind( const void *key, const void **rootp, int(*cmp)(const void *, const void *) );
280 void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void *) );
281 void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
282 void tdestroy( void *root, void (*free_node)(void *nodep) );
283 #else // HAVE_SEARCH_H
284 # ifndef HAVE_TDESTROY
285 #  define tdestroy vlc_tdestroy
286 # endif
287 #endif
288
289 /* Random numbers */
290 #ifndef HAVE_NRAND48
291 double erand48 (unsigned short subi[3]);
292 long jrand48 (unsigned short subi[3]);
293 long nrand48 (unsigned short subi[3]);
294 #endif
295
296 #ifdef __ANDROID__
297 # undef __linux__
298 # ifndef __cplusplus
299 #  define __cplusplus 0
300 # endif
301 # include <pthread.h>
302 # if __cplusplus == 0
303 #  undef __cplusplus
304 # endif
305 char *tempnam(const char *, const char *);
306 #endif // ANDROID
307
308 #endif /* !LIBVLC_FIXUPS_H */