int len;
len = MultiByteToWideChar( fromCP, 0, string, -1, NULL, 0 );
- if( len == 0 );
+ if( len == 0 )
return NULL;
wchar_t wide[len];
*/
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 */
*/
return _wfopen( wpath, wmode );
}
- else
- {
- /* for Windows Me/98/95 */
- const char *local_name = ToLocale( filename );
+#endif
+ const char *local_name = ToLocale( filename );
- if( local_name != NULL )
- {
- FILE *p_file = fopen( local_name, mode );
- LocaleFree( local_name );
- return p_file;
- }
- 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
+ if( local_name != NULL )
+ {
+ FILE *stream = fopen( local_name, mode );
+ LocaleFree( local_name );
+ return stream;
}
-#endif
+ else
+ errno = ENOENT;
+
+ return NULL;
}
/**
void *utf8_opendir( const char *dirname )
{
+ /* TODO: support for WinNT non-ACP filenames */
const char *local_name = ToLocale( dirname );
if( local_name != NULL )
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 )
{
return _wstati64( wpath, (struct _stati64 *)buf );
}
- else
- {
- /* for Windows Me/98/95 */
- const char *local_name = ToLocale( filename );
+#endif
+#ifdef HAVE_SYS_STAT_H
+ const char *local_name = ToLocale( filename );
- if( local_name != NULL )
- {
- int res = _stati64( 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
+ 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;
}