]> git.sesse.net Git - vlc/blob - include/vlc_fixups.h
Start moving replacement functions to a static import library
[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 #ifdef __MINGW32_VERSION
30 # if __MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION < 14
31 #  error This mingw-runtime is too old, it has a broken vsnprintf
32 # endif
33 /* mingw-runtime provides the whole printf family in a c99 compliant way. */
34 /* the way to enable this is to define __USE_MINGW_ANSI_STDIO, or something
35  * such as _ISOC99_SOURCE; the former is done by configure.ac */
36 /* This isn't done here, since some modules don't include config.h and
37  * therefore this as the first include file */
38 #elif defined UNDER_CE
39 # error Window CE support for *printf needs fixing.
40 #endif
41
42 #ifndef HAVE_STRDUP
43 char *strdup (const char *);
44 #endif
45
46 #ifndef HAVE_VASPRINTF
47 # include <stdarg.h>
48 int vasprintf (char **, const char *, va_list);
49 #endif
50
51 #ifndef HAVE_ASPRINTF
52 int asprintf (char **, const char *, ...);
53 #endif
54
55 #ifndef HAVE_STRNLEN
56 # include <stddef.h>
57 size_t strnlen (const char *, size_t);
58 #endif
59
60 #ifndef HAVE_STRNDUP
61 # include <stddef.h>
62 char *strndup (const char *, size_t);
63 #endif
64
65 #ifndef HAVE_STRLCPY
66 # include <stddef.h>
67 size_t strlcpy (char *, const char *, size_t);
68 #endif
69
70 #ifndef HAVE_STRTOF
71 float strtof (const char *, char **);
72 #endif
73
74 #ifndef HAVE_ATOF
75 double atof (const char *);
76 #endif
77
78 #ifndef HAVE_STRTOLL
79 long long int strtoll (const char *, char **, int);
80 #endif
81
82 #ifndef HAVE_STRSEP
83 char *strsep (char **, const char *);
84 #endif
85
86 #ifndef HAVE_ATOLL
87 long long atoll (const char *);
88 #endif
89
90 #ifndef HAVE_LLDIV
91 typedef struct {
92     long long quot; /* Quotient. */
93     long long rem;  /* Remainder. */
94 } lldiv_t;
95
96 lldiv_t lldiv (long long, long long);
97 #endif
98
99 #ifndef HAVE_GETENV
100 static inline char *getenv (const char *name)
101 {
102     (void)name;
103     return NULL;
104 }
105 #endif
106
107 #ifndef HAVE_STRCASECMP
108 # ifndef HAVE_STRICMP
109 #  include <ctype.h>
110 static inline int strcasecmp (const char *s1, const char *s2)
111 {
112     for (size_t i = 0;; i++)
113     {
114         int d = tolower (s1[i]) - tolower (s2[i]);
115         if (d || !s1[i]) return d;
116     }
117     return 0;
118 }
119 # else
120 #  define strcasecmp stricmp
121 # endif
122 #endif
123
124 #ifndef HAVE_STRNCASECMP
125 # ifndef HAVE_STRNICMP
126 #  include <ctype.h>
127 static inline int strncasecmp (const char *s1, const char *s2, size_t n)
128 {
129     for (size_t i = 0; i < n; i++)
130     {
131         int d = tolower (s1[i]) - tolower (s2[i]);
132         if (d || !s1[i]) return d;
133     }
134     return 0;
135 }
136 # else
137 #  define strncasecmp strnicmp
138 # endif
139 #endif
140
141 #ifndef HAVE_STRCASESTR
142 # ifndef HAVE_STRISTR
143 #  define strcasestr vlc_strcasestr
144 # else
145 #  define strcasestr stristr
146 # endif
147 #endif
148
149 #ifndef HAVE_LOCALTIME_R
150 /* If localtime_r() is not provided, we assume localtime() uses
151  * thread-specific storage. */
152 # include <time.h>
153 static inline struct tm *localtime_r (const time_t *timep, struct tm *result)
154 {
155     struct tm *s = localtime (timep);
156     if (s == NULL)
157         return NULL;
158
159     *result = *s;
160     return result;
161 }
162 static inline struct tm *gmtime_r (const time_t *timep, struct tm *result)
163 {
164     struct tm *s = gmtime (timep);
165     if (s == NULL)
166         return NULL;
167
168     *result = *s;
169     return result;
170 }
171 #endif
172
173 /* Alignment of critical static data structures */
174 #ifdef ATTRIBUTE_ALIGNED_MAX
175 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
176 #else
177 #   define ATTR_ALIGN(align)
178 #endif
179
180 #ifndef HAVE_USELOCALE
181 typedef void *locale_t;
182 # define newlocale( a, b, c ) ((locale_t)0)
183 # define uselocale( a ) ((locale_t)0)
184 # define freelocale( a ) (void)0
185 #endif
186
187 #ifdef WIN32
188 # include <dirent.h>
189 # define opendir Use_utf8_opendir_or_vlc_wopendir_instead!
190 # define readdir Use_utf8_readdir_or_vlc_wreaddir_instead!
191 # define closedir vlc_wclosedir
192 #endif
193
194 /* libintl support */
195 #define _(str) vlc_gettext (str)
196
197 #if defined (ENABLE_NLS)
198 # include <libintl.h>
199 #endif
200
201 #define N_(str) gettext_noop (str)
202 #define gettext_noop(str) (str)
203
204 #ifdef UNDER_CE
205 static inline void rewind ( FILE *stream )
206 {
207     fseek(stream, 0L, SEEK_SET);
208     clearerr(stream);
209 }
210 #endif
211
212 #endif /* !LIBVLC_FIXUPS_H */