Commit 9d08f2d7 authored by Gildas Bazin's avatar Gildas Bazin

* src/misc/*, src/extras/libc.c: bunch of WinCE fixes.

parent d87b1696
...@@ -87,6 +87,7 @@ char *vlc_strndup( const char *string, size_t n ) ...@@ -87,6 +87,7 @@ char *vlc_strndup( const char *string, size_t n )
int vlc_strcasecmp( const char *s1, const char *s2 ) int vlc_strcasecmp( const char *s1, const char *s2 )
{ {
int i_delta = 0; int i_delta = 0;
if( !s1 || !s2 ) return -1;
while( !i_delta && *s1 && *s2 ) while( !i_delta && *s1 && *s2 )
{ {
...@@ -94,17 +95,19 @@ int vlc_strcasecmp( const char *s1, const char *s2 ) ...@@ -94,17 +95,19 @@ int vlc_strcasecmp( const char *s1, const char *s2 )
if( *s1 >= 'A' && *s1 <= 'Z' ) if( *s1 >= 'A' && *s1 <= 'Z' )
{ {
i_delta -= 'A' - 'a'; i_delta -= ('A' - 'a');
} }
if( *s2 >= 'A' && *s2 <= 'Z' ) if( *s2 >= 'A' && *s2 <= 'Z' )
{ {
i_delta += 'A' - 'a'; i_delta += ('A' - 'a');
} }
s1++; s2++; s1++; s2++;
} }
if( !i_delta && (*s1 || *s2) ) i_delta = *s1 ? 1 : -1;
return i_delta; return i_delta;
} }
#endif #endif
...@@ -116,8 +119,9 @@ int vlc_strcasecmp( const char *s1, const char *s2 ) ...@@ -116,8 +119,9 @@ int vlc_strcasecmp( const char *s1, const char *s2 )
int vlc_strncasecmp( const char *s1, const char *s2, size_t n ) int vlc_strncasecmp( const char *s1, const char *s2, size_t n )
{ {
int i_delta = 0; int i_delta = 0;
if( !s1 || !s2 ) return -1;
while( n-- && !i_delta && *s1 ) while( n-- && !i_delta && *s1 && *s2 )
{ {
i_delta = *s1 - *s2; i_delta = *s1 - *s2;
...@@ -134,6 +138,8 @@ int vlc_strncasecmp( const char *s1, const char *s2, size_t n ) ...@@ -134,6 +138,8 @@ int vlc_strncasecmp( const char *s1, const char *s2, size_t n )
s1++; s2++; s1++; s2++;
} }
if( !n && !i_delta && (*s1 || *s2) ) i_delta = *s1 ? 1 : -1;
return i_delta; return i_delta;
} }
#endif #endif
......
...@@ -917,10 +917,23 @@ int config_CreateDir( vlc_object_t *p_this, char *psz_dirname ) ...@@ -917,10 +917,23 @@ int config_CreateDir( vlc_object_t *p_this, char *psz_dirname )
#if defined( UNDER_CE ) #if defined( UNDER_CE )
{ {
wchar_t psz_new[ MAX_PATH ]; wchar_t psz_new[ MAX_PATH ];
MultiByteToWideChar( CP_ACP, 0, psz_dirname, -1, psz_new, MAX_PATH ); char psz_mod[MAX_PATH];
int i = 0;
/* Convert '/' into '\' */
while( *psz_dirname )
{
if( *psz_dirname == '/' ) psz_mod[i] = '\\';
else psz_mod[i] = *psz_dirname;
psz_dirname++;
i++;
}
psz_mod[i] = 0;
MultiByteToWideChar( CP_ACP, 0, psz_mod, -1, psz_new, MAX_PATH );
if( CreateDirectory( psz_new, NULL ) ) if( CreateDirectory( psz_new, NULL ) )
{ {
msg_Err( p_this, "could not create %s", psz_dirname ); msg_Err( p_this, "could not create %s", psz_mod );
} }
} }
...@@ -1543,7 +1556,7 @@ char *config_GetHomeDir( void ) ...@@ -1543,7 +1556,7 @@ char *config_GetHomeDir( void )
struct passwd *p_pw = NULL; struct passwd *p_pw = NULL;
#endif #endif
#if defined(WIN32) || defined(UNDER_CE) #if defined(WIN32) && !defined(UNDER_CE)
typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD, typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
LPSTR ); LPSTR );
#ifndef CSIDL_FLAG_CREATE #ifndef CSIDL_FLAG_CREATE
...@@ -1567,10 +1580,7 @@ char *config_GetHomeDir( void ) ...@@ -1567,10 +1580,7 @@ char *config_GetHomeDir( void )
if ( SHGetFolderPath != NULL ) if ( SHGetFolderPath != NULL )
{ {
p_homedir = (char *)malloc( MAX_PATH ); p_homedir = (char *)malloc( MAX_PATH );
if( !p_homedir ) if( !p_homedir ) return NULL;
{
return NULL;
}
/* get the "Application Data" folder for the current user */ /* get the "Application Data" folder for the current user */
if( S_OK == SHGetFolderPath( NULL, if( S_OK == SHGetFolderPath( NULL,
...@@ -1582,9 +1592,24 @@ char *config_GetHomeDir( void ) ...@@ -1582,9 +1592,24 @@ char *config_GetHomeDir( void )
return p_homedir; return p_homedir;
} }
free( p_homedir ); free( p_homedir );
p_homedir = NULL;
} }
FreeLibrary( shfolder_dll ); FreeLibrary( shfolder_dll );
} }
#elif defined(UNDER_CE)
wchar_t p_whomedir[MAX_PATH];
/* get the "Application Data" folder for the current user */
if( SHGetSpecialFolderPath( NULL, p_whomedir, CSIDL_APPDATA, 1 ) )
{
p_homedir = (char *)malloc( MAX_PATH );
if( !p_homedir ) return NULL;
sprintf( p_homedir, "%ls", p_whomedir );
return p_homedir;
}
#endif #endif
#if defined(HAVE_GETPWUID) #if defined(HAVE_GETPWUID)
......
...@@ -676,8 +676,11 @@ void __module_Unneed( vlc_object_t * p_this, module_t * p_module ) ...@@ -676,8 +676,11 @@ void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
static void AllocateAllPlugins( vlc_object_t *p_this ) static void AllocateAllPlugins( vlc_object_t *p_this )
{ {
/* Yes, there are two NULLs because we replace one with "plugin-path". */ /* Yes, there are two NULLs because we replace one with "plugin-path". */
char * path[] = { "modules", PLUGIN_PATH, "plugins", NULL, #ifdef WIN32
NULL }; char * path[] = { "modules", "", "plugins", 0, 0 };
#else
char * path[] = { "modules", PLUGIN_PATH, "plugins", 0, 0 };
#endif
char ** ppsz_path = path; char ** ppsz_path = path;
char * psz_fullpath; char * psz_fullpath;
...@@ -688,12 +691,14 @@ static void AllocateAllPlugins( vlc_object_t *p_this ) ...@@ -688,12 +691,14 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
for( ; *ppsz_path != NULL ; ppsz_path++ ) for( ; *ppsz_path != NULL ; ppsz_path++ )
{ {
#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \ if( !(*ppsz_path)[0] ) continue;
|| ( defined( WIN32 ) && !defined( UNDER_CE ) )
#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
/* Handle relative as well as absolute paths */ /* Handle relative as well as absolute paths */
#ifdef WIN32 #ifdef WIN32
if( !(*ppsz_path)[0] || (*ppsz_path)[1] != ':' ) if( (*ppsz_path)[0] != '\\' && (*ppsz_path)[0] != '/' &&
(*ppsz_path)[1] != ':' )
#else #else
if( (*ppsz_path)[0] != '/' ) if( (*ppsz_path)[0] != '/' )
#endif #endif
...@@ -742,11 +747,10 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir, ...@@ -742,11 +747,10 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
{ {
#if defined( UNDER_CE ) || defined( _MSC_VER ) #if defined( UNDER_CE ) || defined( _MSC_VER )
#ifdef UNDER_CE #ifdef UNDER_CE
wchar_t psz_path[MAX_PATH + 256]; wchar_t psz_wpath[MAX_PATH + 256];
wchar_t psz_wdir[MAX_PATH]; wchar_t psz_wdir[MAX_PATH];
#else
char psz_path[MAX_PATH + 256];
#endif #endif
char psz_path[MAX_PATH + 256];
WIN32_FIND_DATA finddata; WIN32_FIND_DATA finddata;
HANDLE handle; HANDLE handle;
unsigned int rc; unsigned int rc;
...@@ -770,17 +774,20 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir, ...@@ -770,17 +774,20 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
if( !(rc & FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */ if( !(rc & FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
/* Parse all files in the directory */ /* Parse all files in the directory */
swprintf( psz_path, L"%s\\*.*", psz_dir ); swprintf( psz_wpath, L"%ls\\*", psz_wdir );
#else #else
rc = GetFileAttributes( psz_dir ); rc = GetFileAttributes( psz_dir );
if( !(rc & FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */ if( !(rc & FILE_ATTRIBUTE_DIRECTORY) ) return; /* Not a directory */
#endif
/* Parse all files in the directory */ /* Parse all files in the directory */
sprintf( psz_path, "%s\\*.*", psz_dir ); sprintf( psz_path, "%s\\*", psz_dir );
#endif
#ifdef UNDER_CE
handle = FindFirstFile( psz_wpath, &finddata );
#else
handle = FindFirstFile( psz_path, &finddata ); handle = FindFirstFile( psz_path, &finddata );
#endif
if( handle == INVALID_HANDLE_VALUE ) if( handle == INVALID_HANDLE_VALUE )
{ {
/* Empty directory */ /* Empty directory */
...@@ -792,40 +799,35 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir, ...@@ -792,40 +799,35 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
{ {
#ifdef UNDER_CE #ifdef UNDER_CE
unsigned int i_len = wcslen( finddata.cFileName ); unsigned int i_len = wcslen( finddata.cFileName );
swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName ); swprintf( psz_wpath, L"%ls\\%ls", psz_wdir, finddata.cFileName );
sprintf( psz_path, "%s\\%ls", psz_dir, finddata.cFileName );
#else #else
unsigned int i_len = strlen( finddata.cFileName ); unsigned int i_len = strlen( finddata.cFileName );
sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
#endif
/* Skip ".", ".." and anything starting with "." */ /* Skip ".", ".." and anything starting with "." */
if( !*finddata.cFileName || *finddata.cFileName == '.' ) if( !*finddata.cFileName || *finddata.cFileName == '.' )
{ {
if( !FindNextFile( handle, &finddata ) ) break; if( !FindNextFile( handle, &finddata ) ) break;
continue; continue;
} }
sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
#endif
#ifdef UNDER_CE
if( GetFileAttributes( psz_wpath ) & FILE_ATTRIBUTE_DIRECTORY )
#else
if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY ) if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
#endif
{ {
AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 ); AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
} }
else if( i_len > strlen( LIBEXT ) else if( i_len > strlen( LIBEXT )
#ifdef UNDER_CE
)
#else
/* We only load files ending with LIBEXT */ /* We only load files ending with LIBEXT */
&& !strncasecmp( psz_path + strlen( psz_path) && !strncasecmp( psz_path + strlen( psz_path)
- strlen( LIBEXT ), - strlen( LIBEXT ),
LIBEXT, strlen( LIBEXT ) ) ) LIBEXT, strlen( LIBEXT ) ) )
#endif
{ {
#ifdef UNDER_CE
char psz_filename[MAX_PATH];
WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_path, -1,
psz_filename, MAX_PATH, NULL, NULL );
psz_file = psz_filename;
#else
psz_file = psz_path; psz_file = psz_path;
#endif
AllocatePluginFile( p_this, psz_file, 0, 0 ); AllocatePluginFile( p_this, psz_file, 0, 0 );
} }
...@@ -1266,12 +1268,21 @@ static int LoadModule( vlc_object_t *p_this, char *psz_file, ...@@ -1266,12 +1268,21 @@ static int LoadModule( vlc_object_t *p_this, char *psz_file,
} }
#elif defined(HAVE_DL_WINDOWS) #elif defined(HAVE_DL_WINDOWS)
#ifdef UNDER_CE
{
wchar_t psz_wfile[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, psz_file, -1, psz_wfile, MAX_PATH );
handle = LoadLibrary( psz_wfile );
}
#else
handle = LoadLibrary( psz_file ); handle = LoadLibrary( psz_file );
#endif
if( handle == NULL ) if( handle == NULL )
{ {
char *psz_err = GetWindowsError(); char *psz_err = GetWindowsError();
msg_Warn( p_this, "cannot load module `%s' (%s)", psz_file, psz_err ); msg_Warn( p_this, "cannot load module `%s' (%s)", psz_file, psz_err );
free( psz_err ); free( psz_err );
return -1;
} }
#elif defined(HAVE_DL_DLOPEN) && defined(RTLD_NOW) #elif defined(HAVE_DL_DLOPEN) && defined(RTLD_NOW)
...@@ -1528,13 +1539,17 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1528,13 +1539,17 @@ static void CacheLoad( vlc_object_t *p_this )
if( p_this->p_libvlc->p_module_bank->b_cache_delete ) if( p_this->p_libvlc->p_module_bank->b_cache_delete )
{ {
msg_Dbg( p_this, "removing plugins cache file %s", psz_filename ); msg_Dbg( p_this, "removing plugins cache file %s", psz_filename );
#if !defined( UNDER_CE )
unlink( psz_filename ); unlink( psz_filename );
#else
msg_Err( p_this, "FIXME, unlink not implemented" );
#endif
return; return;
} }
msg_Dbg( p_this, "loading plugins cache file %s", psz_filename ); msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
file = fopen( psz_filename, "r" ); file = fopen( psz_filename, "rb" );
if( !file ) if( !file )
{ {
msg_Warn( p_this, "could not open plugins cache file %s for reading", msg_Warn( p_this, "could not open plugins cache file %s for reading",
...@@ -1808,7 +1823,7 @@ static void CacheSave( vlc_object_t *p_this ) ...@@ -1808,7 +1823,7 @@ static void CacheSave( vlc_object_t *p_this )
msg_Dbg( p_this, "saving plugins cache file %s", psz_filename ); msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );
file = fopen( psz_filename, "w" ); file = fopen( psz_filename, "wb" );
if( !file ) if( !file )
{ {
msg_Warn( p_this, "could not open plugins cache file %s for writing", msg_Warn( p_this, "could not open plugins cache file %s for writing",
......
...@@ -47,13 +47,18 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) ...@@ -47,13 +47,18 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
WSADATA Data; WSADATA Data;
/* Get our full path */ /* Get our full path */
#if !defined( UNDER_CE )
if( ppsz_argv[0] ) if( ppsz_argv[0] )
{ {
char psz_path[MAX_PATH]; char psz_path[MAX_PATH];
char *psz_vlc; char *psz_vlc;
#if defined( UNDER_CE )
strcpy( psz_path, ppsz_argv[0] );
psz_vlc = strrchr( psz_path, '\\' );
if( psz_vlc ) psz_vlc++;
#else
GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc ); GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc );
#endif
if( psz_vlc > psz_path && psz_vlc[-1] == '\\' ) if( psz_vlc > psz_path && psz_vlc[-1] == '\\' )
{ {
...@@ -66,7 +71,6 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) ...@@ -66,7 +71,6 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
} }
} }
else else
#endif
{ {
p_this->p_libvlc->psz_vlcpath = strdup( "" ); p_this->p_libvlc->psz_vlcpath = strdup( "" );
} }
......
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