]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
vlc_tdestroy: safe replacement for GNU tdestroy()
[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 #ifndef HAVE_REWIND
47 # include <stdio.h> /* FILE */
48 #endif
49
50 #if !defined (HAVE_STRLCPY) || \
51     !defined (HAVE_STRNDUP) || \
52     !defined (HAVE_STRNLEN) || \
53     !defined (HAVE_GETCWD)
54 # include <stddef.h> /* size_t */
55 #endif
56
57 #ifndef HAVE_VASPRINTF
58 # include <stdarg.h> /* va_list */
59 #endif
60
61 #ifndef HAVE_GETPID
62 # include <sys/types.h> /* pid_t */
63 #endif
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69 #ifndef HAVE_STRDUP
70 char *strdup (const char *);
71 #endif
72
73 #ifndef HAVE_VASPRINTF
74 int vasprintf (char **, const char *, va_list);
75 #endif
76
77 #ifndef HAVE_ASPRINTF
78 int asprintf (char **, const char *, ...);
79 #endif
80
81 #ifndef HAVE_STRNLEN
82 size_t strnlen (const char *, size_t);
83 #endif
84
85 #ifndef HAVE_STRNDUP
86 char *strndup (const char *, size_t);
87 #endif
88
89 #ifndef HAVE_STRLCPY
90 size_t strlcpy (char *, const char *, size_t);
91 #endif
92
93 #ifndef HAVE_STRTOF
94 float strtof (const char *, char **);
95 #endif
96
97 #ifndef HAVE_ATOF
98 double atof (const char *);
99 #endif
100
101 #ifndef HAVE_STRTOLL
102 long long int strtoll (const char *, char **, int);
103 #endif
104
105 #ifndef HAVE_STRSEP
106 char *strsep (char **, const char *);
107 #endif
108
109 #ifndef HAVE_ATOLL
110 long long atoll (const char *);
111 #endif
112
113 #ifndef HAVE_LLDIV
114 lldiv_t lldiv (long long, long long);
115 #endif
116
117 #ifndef HAVE_STRCASECMP
118 int strcasecmp (const char *, const char *);
119 #endif
120
121 #ifndef HAVE_STRNCASECMP
122 int strncasecmp (const char *, const char *, size_t);
123 #endif
124
125 #ifndef HAVE_STRCASESTR
126 char *strcasestr (const char *, const char *);
127 #endif
128
129 #ifndef HAVE_GMTIME_R
130 struct tm *gmtime_r (const time_t *, struct tm *);
131 #endif
132
133 #ifndef HAVE_LOCALTIME_R
134 struct tm *localtime_r (const time_t *, struct tm *);
135 #endif
136
137 #ifndef HAVE_REWIND
138 void rewind (FILE *);
139 #endif
140
141 #ifndef HAVE_GETCWD
142 char *getcwd (char *buf, size_t size);
143 #endif
144
145 #ifndef HAVE_GETPID
146 pid_t getpid (void);
147 #endif
148
149 #ifndef HAVE_STRTOK_R
150 char *strtok_r(char *, const char *, char **);
151 #endif
152
153 #ifdef __cplusplus
154 } /* extern "C" */
155 #endif
156
157 #ifndef HAVE_GETENV
158 static inline char *getenv (const char *name)
159 {
160     (void)name;
161     return NULL;
162 }
163 #endif
164
165 /* Alignment of critical static data structures */
166 #ifdef ATTRIBUTE_ALIGNED_MAX
167 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
168 #else
169 #   define ATTR_ALIGN(align)
170 #endif
171
172 #ifndef HAVE_USELOCALE
173 #define LC_NUMERIC_MASK 0
174 typedef void *locale_t;
175 static inline locale_t uselocale(locale_t loc)
176 {
177     (void)loc;
178     return NULL;
179 }
180 static inline void freelocale(locale_t loc)
181 {
182     (void)loc;
183 }
184 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
185 {
186     (void)mask; (void)locale; (void)base;
187     return NULL;
188 }
189 #endif
190
191 #ifdef WIN32
192 # include <dirent.h>
193 # define opendir Use_utf8_opendir_or_vlc_wopendir_instead!
194 # define readdir Use_utf8_readdir_or_vlc_wreaddir_instead!
195 # define closedir vlc_wclosedir
196 #endif
197
198 /* libintl support */
199 #define _(str)            vlc_gettext (str)
200 #define N_(str)           gettext_noop (str)
201 #define gettext_noop(str) (str)
202
203 #ifndef HAVE_SWAB
204 void swab (const void *, void *, ssize_t);
205 #endif
206
207 /* Socket stuff */
208 #ifndef HAVE_INET_PTON
209 # define inet_pton vlc_inet_pton
210 #endif
211
212 #ifndef HAVE_INET_NTOP
213 # define inet_ntop vlc_inet_ntop
214 #endif
215
216 #ifndef HAVE_POLL
217 enum
218 {
219     POLLIN=1,
220     POLLOUT=2,
221     POLLPRI=4,
222     POLLERR=8,  // unsupported stub
223     POLLHUP=16, // unsupported stub
224     POLLNVAL=32 // unsupported stub
225 };
226
227 struct pollfd
228 {
229     int fd;
230     unsigned events;
231     unsigned revents;
232 };
233
234 # define poll(a, b, c) vlc_poll(a, b, c)
235 #endif
236
237 #ifndef HAVE_TDESTROY
238 # define tdestroy vlc_tdestroy
239 #endif
240
241 #endif /* !LIBVLC_FIXUPS_H */