vlc_fixups.h 5.04 KB
Newer Older
1 2 3
/*****************************************************************************
 * fixups.h: portability fixups included from config.h
 *****************************************************************************
4
 * Copyright © 1998-2008 the VideoLAN project
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/**
 * \file
 * This file is a collection of portability fixes
 */

26 27 28
#ifndef LIBVLC_FIXUPS_H
# define LIBVLC_FIXUPS_H 1

29 30 31 32 33 34 35 36 37 38 39 40 41
#ifdef __MINGW32_VERSION
# if __MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION < 14
#  error This mingw-runtime is too old, it has a broken vsnprintf
# endif
/* mingw-runtime provides the whole printf family in a c99 compliant way. */
/* the way to enable this is to define __USE_MINGW_ANSI_STDIO, or something
 * such as _ISOC99_SOURCE; the former is done by configure.ac */
/* This isn't done here, since some modules don't include config.h and
 * therefore this as the first include file */
#elif defined UNDER_CE
# error Window CE support for *printf needs fixing.
#endif

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
42
#ifndef HAVE_STRDUP
43
char *strdup (const char *);
44 45 46
#endif

#ifndef HAVE_VASPRINTF
47
# include <stdarg.h>
48
int vasprintf (char **, const char *, va_list);
49 50 51
#endif

#ifndef HAVE_ASPRINTF
52
int asprintf (char **, const char *, ...);
53 54
#endif

55
#ifndef HAVE_STRNLEN
56 57
# include <stddef.h>
size_t strnlen (const char *, size_t);
58 59
#endif

60
#ifndef HAVE_STRNDUP
61 62
# include <stddef.h>
char *strndup (const char *, size_t);
63 64 65
#endif

#ifndef HAVE_STRLCPY
66 67
# include <stddef.h>
size_t strlcpy (char *, const char *, size_t);
68 69 70
#endif

#ifndef HAVE_STRTOF
71
float strtof (const char *, char **);
72 73
#endif

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
74
#ifndef HAVE_ATOF
75
double atof (const char *);
76 77 78
#endif

#ifndef HAVE_STRTOLL
79
long long int strtoll (const char *, char **, int);
80 81
#endif

82
#ifndef HAVE_STRSEP
83
char *strsep (char **, const char *);
84 85
#endif

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
86
#ifndef HAVE_ATOLL
87
long long atoll (const char *);
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
88 89
#endif

90
#ifndef HAVE_LLDIV
91 92 93 94 95
typedef struct {
    long long quot; /* Quotient. */
    long long rem;  /* Remainder. */
} lldiv_t;

96
lldiv_t lldiv (long long, long long);
97 98 99
#endif

#ifndef HAVE_GETENV
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
100
static inline char *getenv (const char *name)
101 102 103 104
{
    (void)name;
    return NULL;
}
105 106 107 108
#endif

#ifndef HAVE_STRCASECMP
# ifndef HAVE_STRICMP
109 110 111 112 113 114
#  include <ctype.h>
static inline int strcasecmp (const char *s1, const char *s2)
{
    for (size_t i = 0;; i++)
    {
        int d = tolower (s1[i]) - tolower (s2[i]);
115
        if (d || !s1[i]) return d;
116 117 118
    }
    return 0;
}
119 120 121 122 123 124 125
# else
#  define strcasecmp stricmp
# endif
#endif

#ifndef HAVE_STRNCASECMP
# ifndef HAVE_STRNICMP
126 127 128 129 130 131
#  include <ctype.h>
static inline int strncasecmp (const char *s1, const char *s2, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        int d = tolower (s1[i]) - tolower (s2[i]);
132
        if (d || !s1[i]) return d;
133 134 135
    }
    return 0;
}
136 137 138 139 140 141 142 143 144 145 146 147 148
# else
#  define strncasecmp strnicmp
# endif
#endif

#ifndef HAVE_STRCASESTR
# ifndef HAVE_STRISTR
#  define strcasestr vlc_strcasestr
# else
#  define strcasestr stristr
# endif
#endif

149 150 151 152
#ifndef HAVE_LOCALTIME_R
/* If localtime_r() is not provided, we assume localtime() uses
 * thread-specific storage. */
# include <time.h>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
153
static inline struct tm *localtime_r (const time_t *timep, struct tm *result)
154 155 156 157 158 159 160 161
{
    struct tm *s = localtime (timep);
    if (s == NULL)
        return NULL;

    *result = *s;
    return result;
}
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
162 163 164 165 166 167 168 169 170
static inline struct tm *gmtime_r (const time_t *timep, struct tm *result)
{
    struct tm *s = gmtime (timep);
    if (s == NULL)
        return NULL;

    *result = *s;
    return result;
}
171 172
#endif

173 174 175 176 177 178 179
/* Alignment of critical static data structures */
#ifdef ATTRIBUTE_ALIGNED_MAX
#   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
#else
#   define ATTR_ALIGN(align)
#endif

180 181 182 183 184 185 186
#ifndef HAVE_USELOCALE
typedef void *locale_t;
# define newlocale( a, b, c ) ((locale_t)0)
# define uselocale( a ) ((locale_t)0)
# define freelocale( a ) (void)0
#endif

187
#ifdef WIN32
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
188
# include <dirent.h>
189 190 191 192 193
# define opendir Use_utf8_opendir_or_vlc_wopendir_instead!
# define readdir Use_utf8_readdir_or_vlc_wreaddir_instead!
# define closedir vlc_wclosedir
#endif

194
/* libintl support */
195
#define _(str) vlc_gettext (str)
196 197 198 199 200 201 202 203

#if defined (ENABLE_NLS)
# include <libintl.h>
#endif

#define N_(str) gettext_noop (str)
#define gettext_noop(str) (str)

204 205 206 207 208 209 210 211
#ifdef UNDER_CE
static inline void rewind ( FILE *stream )
{
    fseek(stream, 0L, SEEK_SET);
    clearerr(stream);
}
#endif

212
#endif /* !LIBVLC_FIXUPS_H */