Commit dc4a1ad0 authored by Antoine Cellerier's avatar Antoine Cellerier

Backport win9x file opening fixes ( [15501], [15506], [15509], [15510],...

Backport win9x file opening fixes ( [15501], [15506], [15509], [15510], [15511], [15512] and [15518])
parent 5fd83d54
......@@ -140,18 +140,18 @@ static char *MB2MB( const char *string, UINT fromCP, UINT toCP )
int len;
len = MultiByteToWideChar( fromCP, 0, string, -1, NULL, 0 );
assert( len > 0 );
wide = (wchar_t *)malloc (len * sizeof (wchar_t));
if( wide == NULL )
if( len == 0 );
return NULL;
wchar_t wide[len];
MultiByteToWideChar( fromCP, 0, string, -1, wide, len );
len = WideCharToMultiByte( toCP, 0, wide, -1, NULL, 0, NULL, NULL );
assert( len > 0 );
if( len == 0 )
return NULL;
out = malloc( len );
WideCharToMultiByte( toCP, 0, wide, -1, out, len, NULL, NULL );
free( wide );
return out;
}
#endif
......@@ -306,19 +306,10 @@ void LocaleFree( const char *str )
*/
FILE *utf8_fopen( const char *filename, const char *mode )
{
#if !(defined (WIN32) || defined (UNDER_CE))
const char *local_name = ToLocale( filename );
if( local_name != NULL )
#if defined (WIN32) || defined (UNDER_CE)
if( GetVersion() < 0x80000000 )
{
FILE *stream = fopen( local_name, mode );
LocaleFree( local_name );
return stream;
}
else
errno = ENOENT;
return NULL;
#else
/* for Windows NT and above */
wchar_t wpath[MAX_PATH + 1];
size_t len = strlen( mode ) + 1;
wchar_t wmode[len];
......@@ -336,7 +327,20 @@ FILE *utf8_fopen( const char *filename, const char *mode )
* We use _wfopen() instead. Same thing for mkdir() and stat().
*/
return _wfopen( wpath, wmode );
}
#endif
const char *local_name = ToLocale( filename );
if( local_name != NULL )
{
FILE *stream = fopen( local_name, mode );
LocaleFree( local_name );
return stream;
}
else
errno = ENOENT;
return NULL;
}
/**
......@@ -399,6 +403,7 @@ int utf8_mkdir( const char *dirname )
void *utf8_opendir( const char *dirname )
{
/* TODO: support for WinNT non-ACP filenames */
const char *local_name = ToLocale( dirname );
if( local_name != NULL )
......@@ -493,21 +498,11 @@ int utf8_scandir( const char *dirname, char ***namelist,
static int utf8_statEx( const char *filename, void *buf,
vlc_bool_t deref )
{
#if !(defined (WIN32) || defined (UNDER_CE))
# ifdef HAVE_SYS_STAT_H
const char *local_name = ToLocale( filename );
if( local_name != NULL )
#if defined (WIN32) || defined (UNDER_CE)
/* retrieve Windows OS version */
if( GetVersion() < 0x80000000 )
{
int res = deref ? stat( local_name, (struct stat *)buf )
: lstat( local_name, (struct stat *)buf );
LocaleFree( local_name );
return res;
}
errno = ENOENT;
# endif
return -1;
#else
/* for Windows NT and above */
wchar_t wpath[MAX_PATH + 1];
if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) )
......@@ -518,7 +513,21 @@ static int utf8_statEx( const char *filename, void *buf,
wpath[MAX_PATH] = L'\0';
return _wstati64( wpath, (struct _stati64 *)buf );
}
#endif
#ifdef HAVE_SYS_STAT_H
const char *local_name = ToLocale( filename );
if( local_name != NULL )
{
int res = deref ? stat( local_name, (struct stat *)buf )
: lstat( local_name, (struct stat *)buf );
LocaleFree( local_name );
return res;
}
errno = ENOENT;
#endif
return -1;
}
......
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