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

Avoid code duplication

parent 9ddc8d6a
......@@ -306,20 +306,7 @@ 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 )
{
FILE *stream = fopen( local_name, mode );
LocaleFree( local_name );
return stream;
}
else
errno = ENOENT;
return NULL;
#else
/* retrieve OS version */
#if defined (WIN32) || defined (UNDER_CE)
if( GetVersion() < 0x80000000 )
{
/* for Windows NT and above */
......@@ -341,43 +328,19 @@ FILE *utf8_fopen( const char *filename, const char *mode )
*/
return _wfopen( wpath, wmode );
}
else
{
/* for Windows Me/98/95 */
#endif
const char *local_name = ToLocale( filename );
if( local_name != NULL )
{
FILE *p_file = fopen( local_name, mode );
FILE *stream = fopen( local_name, mode );
LocaleFree( local_name );
return p_file;
return stream;
}
else
errno = ENOENT;
return NULL;
#if 0
/* Following code might work better in most cases but fails if file
doesn't already exist on call to GetShortPathNameW.
I'll keep it here in case we ever decide to try this first and
then fallback to previous solution if it fails. */
/* we use GetShortFileNameW to get the DOS 8.3 version of the file we need to open */
wchar_t spath[MAX_PATH + 1];
if( GetShortPathNameW( wpath, spath, MAX_PATH ) )
{
char path[ MAX_PATH + 1 ];
int len;
UINT i_codepage = AreFileApisANSI()?GetACP():GetOEMCP();
len = WideCharToMultiByte( i_codepage, 0, spath, -1, NULL, 0, NULL, NULL );
if( len == 0 )
return NULL;
WideCharToMultiByte( i_codepage, 0, spath, -1, path, len, NULL, NULL );
return fopen( path, mode );
}
errno = ENOENT;
return NULL;
#endif
}
#endif
}
/**
......@@ -440,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 )
......@@ -534,21 +498,7 @@ 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 )
{
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
#if defined (WIN32) || defined (UNDER_CE)
/* retrieve Windows OS version */
if( GetVersion() < 0x80000000 )
{
......@@ -564,43 +514,20 @@ static int utf8_statEx( const char *filename, void *buf,
return _wstati64( wpath, (struct _stati64 *)buf );
}
else
{
/* for Windows Me/98/95 */
#endif
#ifdef HAVE_SYS_STAT_H
const char *local_name = ToLocale( filename );
if( local_name != NULL )
{
int res = _stati64( local_name, (struct stat *)buf );
int res = deref ? stat( local_name, (struct stat *)buf )
: lstat( local_name, (struct stat *)buf );
LocaleFree( local_name );
return res;
}
errno = ENOENT;
return -1;
#if 0
/* Following code might work better in most cases but fails if file
doesn't already exist on call to GetShortPathNameW.
I'll keep it here in case we ever decide to try this first and
then fallback to previous solution if it fails. */
/* we use GetShortFileNameW to get the DOS 8.3 version */
wchar_t spath[MAX_PATH + 1];
if( GetShortPathNameW( wpath, spath, MAX_PATH ) )
{
char path[ MAX_PATH + 1 ];
int len;
UINT i_codepage = AreFileApisANSI()?GetACP():GetOEMCP();
len = WideCharToMultiByte( i_codepage, 0, spath, -1, NULL, 0, NULL, NULL );
if( len == 0 )
return -1;
WideCharToMultiByte( i_codepage, 0, spath, -1, path, len, NULL, NULL );
return _stati64( path, (struct _stati64 *)buf );
}
errno = ENOENT;
return -1;
#endif
}
#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