1 /*****************************************************************************
2 * fixups.h: portability fixups included from config.h
3 *****************************************************************************
4 * Copyright © 1998-2008 the VideoLAN project
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.
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.
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 *****************************************************************************/
23 * This file is a collection of portability fixes
26 #ifndef LIBVLC_FIXUPS_H
27 # define LIBVLC_FIXUPS_H 1
33 static inline char *strdup (const char *str)
35 size_t len = strlen (str) + 1;
36 char *res = malloc (len);
37 if (res) memcpy (res, str, len);
42 #ifndef HAVE_VASPRINTF
43 # define vasprintf vlc_vasprintf
47 # define asprintf vlc_asprintf
51 static inline char *strndup (const char *str, size_t max)
53 const char *end = memchr (str, '\0', max);
54 size_t len = end ? (size_t)(end - str) : max;
55 char *res = malloc (len + 1);
58 memcpy (res, str, len);
66 # define strnlen vlc_strnlen
70 # define strlcpy vlc_strlcpy
74 # define atof vlc_atof
79 # define strtof( a, b ) ((float)strtod (a, b))
84 # define atoll vlc_atoll
88 # define strtoll vlc_strtoll
93 long long quot; /* Quotient. */
94 long long rem; /* Remainder. */
97 static inline lldiv_t lldiv (long long numer, long long denom)
99 lldiv_t d = { .quot = numer / denom, .rem = numer % denom };
105 # define scandir vlc_scandir
106 # define alphasort vlc_alphasort
110 static inline getenv (const char *name)
117 #ifndef HAVE_STRCASECMP
118 # ifndef HAVE_STRICMP
119 # define strcasecmp vlc_strcasecmp
121 # define strcasecmp stricmp
125 #ifndef HAVE_STRNCASECMP
126 # ifndef HAVE_STRNICMP
127 # define strncasecmp vlc_strncasecmp
129 # define strncasecmp strnicmp
133 #ifndef HAVE_STRCASESTR
134 # ifndef HAVE_STRISTR
135 # define strcasestr vlc_strcasestr
137 # define strcasestr stristr
141 #ifndef HAVE_LOCALTIME_R
142 /* If localtime_r() is not provided, we assume localtime() uses
143 * thread-specific storage. */
145 static inline struct tm *localtime_r (const time_t *timep, struct tm *result)
147 struct tm *s = localtime (timep);
154 static inline struct tm *gmtime_r (const time_t *timep, struct tm *result)
156 struct tm *s = gmtime (timep);
165 #ifndef HAVE_USELOCALE
166 typedef void *locale_t;
167 # define newlocale( a, b, c ) ((locale_t)0)
168 # define uselocale( a ) ((locale_t)0)
169 # define freelocale( a ) (void)0
174 # define opendir Use_utf8_opendir_or_vlc_wopendir_instead!
175 # define readdir Use_utf8_readdir_or_vlc_wreaddir_instead!
176 # define closedir vlc_wclosedir
179 /* libintl support */
180 #define _(str) vlc_gettext (str)
182 #if defined (ENABLE_NLS)
183 # include <libintl.h>
185 # define dgettext(dom, str) ((char *)(str))
188 #define N_(str) gettext_noop (str)
189 #define gettext_noop(str) (str)
191 #endif /* !LIBVLC_FIXUPS_H */