]> git.sesse.net Git - vlc/commitdiff
* src/misc/*, src/extras/libc.c: bunch of WinCE fixes.
authorGildas Bazin <gbazin@videolan.org>
Tue, 5 Oct 2004 15:30:54 +0000 (15:30 +0000)
committerGildas Bazin <gbazin@videolan.org>
Tue, 5 Oct 2004 15:30:54 +0000 (15:30 +0000)
src/extras/libc.c
src/misc/configuration.c
src/misc/modules.c
src/misc/win32_specific.c

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