00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef LIBVLC_FIXUPS_H
00027 # define LIBVLC_FIXUPS_H 1
00028
00029 #ifndef HAVE_STRDUP
00030 # include <string.h>
00031 # include <stdlib.h>
00032 static inline char *strdup (const char *str)
00033 {
00034 size_t len = strlen (str) + 1;
00035 char *res = (char *)malloc (len);
00036 if (res) memcpy (res, str, len);
00037 return res;
00038 }
00039 #endif
00040
00041 #ifndef HAVE_VASPRINTF
00042 # include <stdio.h>
00043 # include <stdlib.h>
00044 # include <stdarg.h>
00045 static inline int vasprintf (char **strp, const char *fmt, va_list ap)
00046 {
00047 int len = vsnprintf (NULL, 0, fmt, ap) + 1;
00048 char *res = (char *)malloc (len);
00049 if (res == NULL)
00050 return -1;
00051 *strp = res;
00052 return vsprintf (res, fmt, ap);
00053 }
00054 #endif
00055
00056 #ifndef HAVE_ASPRINTF
00057 # include <stdio.h>
00058 # include <stdarg.h>
00059 static inline int asprintf (char **strp, const char *fmt, ...)
00060 {
00061 va_list ap;
00062 int ret;
00063 va_start (ap, fmt);
00064 ret = vasprintf (strp, fmt, ap);
00065 va_end (ap);
00066 return ret;
00067 }
00068 #endif
00069
00070 #ifndef HAVE_STRNLEN
00071 # include <string.h>
00072 static inline size_t strnlen (const char *str, size_t max)
00073 {
00074 const char *end = (const char *) memchr (str, 0, max);
00075 return end ? (size_t)(end - str) : max;
00076 }
00077 #endif
00078
00079 #ifndef HAVE_STRNDUP
00080 # include <string.h>
00081 # include <stdlib.h>
00082 static inline char *strndup (const char *str, size_t max)
00083 {
00084 size_t len = strnlen (str, max);
00085 char *res = (char *) malloc (len + 1);
00086 if (res)
00087 {
00088 memcpy (res, str, len);
00089 res[len] = '\0';
00090 }
00091 return res;
00092 }
00093 #endif
00094
00095 #ifndef HAVE_STRLCPY
00096 # define strlcpy vlc_strlcpy
00097 #endif
00098
00099 #ifndef HAVE_STRTOF
00100 # define strtof( a, b ) ((float)strtod (a, b))
00101 #endif
00102
00103 #ifndef HAVE_ATOF
00104 # define atof( str ) (strtod ((str), (char **)NULL, 10))
00105 #endif
00106
00107 #ifndef HAVE_STRTOLL
00108 # define strtoll vlc_strtoll
00109 #endif
00110
00111 #ifndef HAVE_ATOLL
00112 # define atoll( str ) (strtoll ((str), (char **)NULL, 10))
00113 #endif
00114
00115 #ifndef HAVE_LLDIV
00116 typedef struct {
00117 long long quot;
00118 long long rem;
00119 } lldiv_t;
00120
00121 static inline lldiv_t lldiv (long long numer, long long denom)
00122 {
00123 lldiv_t d = { .quot = numer / denom, .rem = numer % denom };
00124 return d;
00125 }
00126 #endif
00127
00128 #ifndef HAVE_SCANDIR
00129 # define scandir vlc_scandir
00130 # define alphasort vlc_alphasort
00131 #endif
00132
00133 #ifndef HAVE_GETENV
00134 static inline getenv (const char *name)
00135 {
00136 (void)name;
00137 return NULL;
00138 }
00139 #endif
00140
00141 #ifndef HAVE_STRCASECMP
00142 # ifndef HAVE_STRICMP
00143 # include <ctype.h>
00144 static inline int strcasecmp (const char *s1, const char *s2)
00145 {
00146 for (size_t i = 0;; i++)
00147 {
00148 int d = tolower (s1[i]) - tolower (s2[i]);
00149 if (d || !s1[i]) return d;
00150 }
00151 return 0;
00152 }
00153 # else
00154 # define strcasecmp stricmp
00155 # endif
00156 #endif
00157
00158 #ifndef HAVE_STRNCASECMP
00159 # ifndef HAVE_STRNICMP
00160 # include <ctype.h>
00161 static inline int strncasecmp (const char *s1, const char *s2, size_t n)
00162 {
00163 for (size_t i = 0; i < n; i++)
00164 {
00165 int d = tolower (s1[i]) - tolower (s2[i]);
00166 if (d || !s1[i]) return d;
00167 }
00168 return 0;
00169 }
00170 # else
00171 # define strncasecmp strnicmp
00172 # endif
00173 #endif
00174
00175 #ifndef HAVE_STRCASESTR
00176 # ifndef HAVE_STRISTR
00177 # define strcasestr vlc_strcasestr
00178 # else
00179 # define strcasestr stristr
00180 # endif
00181 #endif
00182
00183 #ifndef HAVE_LOCALTIME_R
00184
00185
00186 # include <time.h>
00187 static inline struct tm *localtime_r (const time_t *timep, struct tm *result)
00188 {
00189 struct tm *s = localtime (timep);
00190 if (s == NULL)
00191 return NULL;
00192
00193 *result = *s;
00194 return result;
00195 }
00196 static inline struct tm *gmtime_r (const time_t *timep, struct tm *result)
00197 {
00198 struct tm *s = gmtime (timep);
00199 if (s == NULL)
00200 return NULL;
00201
00202 *result = *s;
00203 return result;
00204 }
00205 #endif
00206
00207
00208 #ifdef ATTRIBUTE_ALIGNED_MAX
00209 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
00210 #else
00211 # define ATTR_ALIGN(align)
00212 #endif
00213
00214 #ifndef HAVE_USELOCALE
00215 typedef void *locale_t;
00216 # define newlocale( a, b, c ) ((locale_t)0)
00217 # define uselocale( a ) ((locale_t)0)
00218 # define freelocale( a ) (void)0
00219 #endif
00220
00221 #ifdef WIN32
00222 # include <dirent.h>
00223 # define opendir Use_utf8_opendir_or_vlc_wopendir_instead!
00224 # define readdir Use_utf8_readdir_or_vlc_wreaddir_instead!
00225 # define closedir vlc_wclosedir
00226 #endif
00227
00228
00229 #define _(str) vlc_gettext (str)
00230
00231 #if defined (ENABLE_NLS)
00232 # include <libintl.h>
00233 #endif
00234
00235 #define N_(str) gettext_noop (str)
00236 #define gettext_noop(str) (str)
00237
00238 #endif