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