Commit f0f90145 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

(Win32) Support stat() for file names outside ANSI Code Page

parent 5243d4df
......@@ -297,15 +297,17 @@ FILE *utf8_fopen( const char *filename, const char *mode )
errno = ENOENT;
return NULL;
#else
wchar_t wpath[MAX_PATH];
wchar_t wmode[4];
wchar_t wpath[MAX_PATH + 1];
size_t len = strlen( mode ) + 1;
wchar_t wmode[len];
if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH - 1)
|| !MultiByteToWideChar( CP_ACP, 0, mode, -1, wmode, 3 ) )
if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH )
|| !MultiByteToWideChar( CP_ACP, 0, mode, len, wmode, len ) )
{
errno = ENOENT;
return NULL;
}
wpath[MAX_PATH] = L'\0';
return _wfopen( wpath, wmode );
#endif
......@@ -317,8 +319,8 @@ FILE *utf8_fopen( const char *filename, const char *mode )
int utf8_mkdir( const char *dirname )
{
#if defined (UNDER_CE) || defined (WIN32)
wchar_t wname[MAX_PATH];
char mod[MAX_PATH];
wchar_t wname[MAX_PATH + 1];
char mod[MAX_PATH + 1];
int i;
/* Convert '/' into '\' */
......@@ -341,6 +343,7 @@ int utf8_mkdir( const char *dirname )
errno = ENOENT;
return -1;
}
wname[MAX_PATH] = L'\0';
if( CreateDirectoryW( wname, NULL ) == 0 )
{
......@@ -397,7 +400,8 @@ const char *utf8_readdir( void *dir )
static int utf8_statEx( const char *filename, void *buf,
vlc_bool_t deref )
{
#ifdef HAVE_SYS_STAT_H
#if !(defined (WIN32) || defined (UNDER_CE))
# ifdef HAVE_SYS_STAT_H
const char *local_name = ToLocale( filename );
if( local_name != NULL )
......@@ -408,8 +412,21 @@ static int utf8_statEx( const char *filename, void *buf,
return res;
}
errno = ENOENT;
#endif
# endif
return -1;
#else
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';
/* struct _stat is just a silly Microsoft alias for struct stat */
return _wstat( wpath, (struct _stat *)buf );
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment