# include <stdarg.h>
static inline int vasprintf (char **strp, const char *fmt, va_list ap)
{
+#ifndef UNDER_CE
int len = vsnprintf (NULL, 0, fmt, ap) + 1;
char *res = (char *)malloc (len);
if (res == NULL)
return -1;
*strp = res;
return vsprintf (res, fmt, ap);
+#else
+ /* HACK: vsnprintf in the WinCE API behaves like
+ * the one in glibc 2.0 and doesn't return the number of characters
+ * it needed to copy the string.
+ * cf http://msdn.microsoft.com/en-us/library/1kt27hek.aspx
+ * and cf the man page of vsnprintf
+ *
+ Guess we need no more than 50 bytes. */
+ int n, size = 50;
+ char *res, *np;
+
+ if ((res = (char *) malloc (size)) == NULL)
+ return -1;
+
+ while (1)
+ {
+ n = vsnprintf (res, size, fmt, ap);
+
+ /* If that worked, return the string. */
+ if (n > -1 && n < size)
+ {
+ *strp = res;
+ return n;
+ }
+
+ /* Else try again with more space. */
+ if (n == -1)
+ size *= 2; /* twice the old size */
+
+ if ((np = (char *) realloc (res, size)) == NULL)
+ {
+ free(res);
+ return -1;
+ }
+ else
+ {
+ res = np;
+ }
+
+ }
+#endif /* UNDER_CE */
}
#endif
/* Define different priorities for WinNT/2K/XP and Win9x/Me */
# define VLC_THREAD_PRIORITY_LOW 0
# define VLC_THREAD_PRIORITY_INPUT \
- (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
+ THREAD_PRIORITY_ABOVE_NORMAL
# define VLC_THREAD_PRIORITY_AUDIO \
- (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
-# define VLC_THREAD_PRIORITY_VIDEO \
- (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
+ THREAD_PRIORITY_HIGHEST
+# define VLC_THREAD_PRIORITY_VIDEO 0
# define VLC_THREAD_PRIORITY_OUTPUT \
- (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
+ THREAD_PRIORITY_ABOVE_NORMAL
# define VLC_THREAD_PRIORITY_HIGHEST \
- (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
+ THREAD_PRIORITY_TIME_CRITICAL
#else
# define VLC_THREAD_PRIORITY_LOW 0
*/
int utf8_open (const char *filename, int flags, mode_t mode)
{
-#if defined (WIN32) || defined (UNDER_CE)
- if (GetVersion() < 0x80000000)
+#ifdef UNDER_CE
+ /*_open translates to wchar internally on WinCE*/
+ return _open (filename, flags, mode);
+#elif defined (WIN32)
+ /* for Windows NT and above */
+ wchar_t wpath[MAX_PATH + 1];
+
+ if (!MultiByteToWideChar (CP_UTF8, 0, filename, -1, wpath, MAX_PATH))
{
- /* for Windows NT and above */
- wchar_t wpath[MAX_PATH + 1];
+ errno = ENOENT;
+ return -1;
+ }
+ wpath[MAX_PATH] = L'\0';
- if (!MultiByteToWideChar (CP_UTF8, 0, filename, -1, wpath, MAX_PATH))
- {
- errno = ENOENT;
- return -1;
- }
- wpath[MAX_PATH] = L'\0';
+ /*
+ * open() cannot open files with non-“ANSI” characters on Windows.
+ * We use _wopen() instead. Same thing for mkdir() and stat().
+ */
+ return _wopen (wpath, flags, mode);
- /*
- * open() cannot open files with non-“ANSI” characters on Windows.
- * We use _wopen() instead. Same thing for mkdir() and stat().
- */
- return _wopen (wpath, flags, mode);
- }
#endif
const char *local_name = ToLocale (filename);
static int utf8_statEx( const char *filename, struct stat *buf,
bool deref )
{
-#if defined (WIN32) || defined (UNDER_CE)
- /* retrieve Windows OS version */
- if( GetVersion() < 0x80000000 )
+#ifdef UNDER_CE
+ /*_stat translates to wchar internally on WinCE*/
+ return _stat( filename, buf );
+#elif defined (WIN32)
+ /* for Windows NT and above */
+ wchar_t wpath[MAX_PATH + 1];
+
+ if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) )
{
- /* for Windows NT and above */
- wchar_t wpath[MAX_PATH + 1];
+ errno = ENOENT;
+ return -1;
+ }
+ wpath[MAX_PATH] = L'\0';
- if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) )
- {
- errno = ENOENT;
- return -1;
- }
- wpath[MAX_PATH] = L'\0';
+ return _wstati64( wpath, buf );
- return _wstati64( wpath, buf );
- }
#endif
#ifdef HAVE_SYS_STAT_H
const char *local_name = ToLocale( filename );
*/
int utf8_unlink( const char *filename )
{
-#if defined (WIN32) || defined (UNDER_CE)
- if( GetVersion() < 0x80000000 )
- {
- /* for Windows NT and above */
- wchar_t wpath[MAX_PATH + 1];
-
- if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) )
- {
- errno = ENOENT;
- return -1;
- }
- wpath[MAX_PATH] = L'\0';
+#ifdef UNDER_CE
+ /*_open translates to wchar internally on WinCE*/
+ return _unlink( filename );
+#elif defined (WIN32)
+ /* for Windows NT and above */
+ wchar_t wpath[MAX_PATH + 1];
- /*
- * unlink() cannot open files with non-“ANSI” characters on Windows.
- * We use _wunlink() instead.
- */
- return _wunlink( wpath );
+ if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) )
+ {
+ errno = ENOENT;
+ return -1;
}
+ wpath[MAX_PATH] = L'\0';
+
+ /*
+ * unlink() cannot open files with non-“ANSI” characters on Windows.
+ * We use _wunlink() instead.
+ */
+ return _wunlink( wpath );
#endif
const char *local_name = ToLocale( filename );