]> git.sesse.net Git - vlc/commitdiff
* src/misc/modules.c:
authorSam Hocevar <sam@videolan.org>
Wed, 27 Oct 2004 13:20:42 +0000 (13:20 +0000)
committerSam Hocevar <sam@videolan.org>
Wed, 27 Oct 2004 13:20:42 +0000 (13:20 +0000)
    + Store plugin cache in a cache/ subdirectory.
    + Encode the endianness and pointer size in the plugin cache filename to
      prevent crashes on multiarch home directories.

include/vlc_config.h
src/misc/modules.c

index 443a84650a3d9320c2ae9699c3d8c625e190cb68..405b9cfc6115344016d38809f2b34a2bc5b41f2e 100644 (file)
@@ -58,7 +58,7 @@
 #  define CONFIG_DIR                    ".vlc"
 #endif
 #define CONFIG_FILE                     "vlcrc"
-#define PLUGINSCACHE_FILE               "vlcplugins"
+#define PLUGINSCACHE_DIR                "cache"
 
 /*****************************************************************************
  * Interface configuration
index 6ff36f6608b0d0194ea51add92df947f4c784868..baeb1a92f95c08c1bd32f6416c0a6f9645f3de98 100644 (file)
@@ -147,6 +147,7 @@ static void   CacheLoad        ( vlc_object_t * );
 static int    CacheLoadConfig  ( module_t *, FILE * );
 static void   CacheSave        ( vlc_object_t * );
 static void   CacheSaveConfig  ( module_t *, FILE * );
+static char * CacheName        ( void );
 static void   CacheMerge       ( vlc_object_t *, module_t *, module_t * );
 static module_cache_t * CacheFind( vlc_object_t *, char *, int64_t, int64_t );
 
@@ -1545,7 +1546,7 @@ static void CacheLoad( vlc_object_t *p_this )
     char *psz_filename, *psz_homedir;
     FILE *file;
     int i, j, i_size, i_read;
-    char p_cachestring[sizeof(PLUGINSCACHE_FILE COPYRIGHT_MESSAGE)];
+    char p_cachestring[sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE)];
     int i_cache;
     module_cache_t **pp_cache = 0;
     int32_t i_file_size;
@@ -1557,12 +1558,8 @@ static void CacheLoad( vlc_object_t *p_this )
         return;
     }
     psz_filename =
-        (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_FILE) +
-                        strlen(psz_homedir) );
-
-    if( psz_filename )
-        sprintf( psz_filename, "%s/" CONFIG_DIR "/" PLUGINSCACHE_FILE,
-                 psz_homedir );
+        (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_DIR "/" ) +
+                        strlen(psz_homedir) + strlen(CacheName()) );
 
     if( !psz_filename )
     {
@@ -1570,6 +1567,9 @@ static void CacheLoad( vlc_object_t *p_this )
         return;
     }
 
+    sprintf( psz_filename, "%s/%s/%s/%s", psz_homedir, CONFIG_DIR,
+             PLUGINSCACHE_DIR, CacheName() );
+
     if( p_this->p_libvlc->p_module_bank->b_cache_delete )
     {
 #if !defined( UNDER_CE )
@@ -1616,10 +1616,10 @@ static void CacheLoad( vlc_object_t *p_this )
     fseek( file, sizeof(i_file_size), SEEK_SET );
 
     /* Check the file is a plugins cache */
-    i_size = sizeof(PLUGINSCACHE_FILE COPYRIGHT_MESSAGE) - 1;
+    i_size = sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE) - 1;
     i_read = fread( p_cachestring, sizeof(char), i_size, file );
     if( i_read != i_size ||
-        memcmp( p_cachestring, PLUGINSCACHE_FILE COPYRIGHT_MESSAGE, i_size ) )
+        memcmp( p_cachestring, PLUGINSCACHE_DIR COPYRIGHT_MESSAGE, i_size ) )
     {
         msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
         fclose( file );
@@ -1841,11 +1841,8 @@ static void CacheSave( vlc_object_t *p_this )
         return;
     }
     psz_filename =
-       (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_FILE) +
-                       strlen(psz_homedir) );
-
-    if( psz_filename )
-        sprintf( psz_filename, "%s/" CONFIG_DIR, psz_homedir );
+       (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_DIR "/" ) +
+                       strlen(psz_homedir) + strlen(CacheName()) );
 
     if( !psz_filename )
     {
@@ -1853,9 +1850,16 @@ static void CacheSave( vlc_object_t *p_this )
         return;
     }
 
+    sprintf( psz_filename, "%s/" CONFIG_DIR, psz_homedir );
+
     config_CreateDir( p_this, psz_filename );
 
-    strcat( psz_filename, "/" PLUGINSCACHE_FILE );
+    strcat( psz_filename, "/" PLUGINSCACHE_DIR );
+
+    config_CreateDir( p_this, psz_filename );
+
+    strcat( psz_filename, "/" );
+    strcat( psz_filename, CacheName() );
 
     msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );
 
@@ -1873,7 +1877,7 @@ static void CacheSave( vlc_object_t *p_this )
     fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file );
 
     /* Contains version number */
-    fprintf( file, PLUGINSCACHE_FILE COPYRIGHT_MESSAGE );
+    fprintf( file, "%s", PLUGINSCACHE_DIR COPYRIGHT_MESSAGE );
 
     i_cache = p_this->p_libvlc->p_module_bank->i_cache;
     pp_cache = p_this->p_libvlc->p_module_bank->pp_cache;
@@ -2007,6 +2011,26 @@ void CacheSaveConfig( module_t *p_module, FILE *file )
     }
 }
 
+/*****************************************************************************
+ * CacheName: Return the cache file name for this platform.
+ *****************************************************************************/
+static char * CacheName( void )
+{
+    static char psz_cachename[32];
+    static vlc_bool_t b_initialised = VLC_FALSE;
+
+    if( !b_initialised )
+    {
+        /* Code int size, pointer size and endianness in the filename */
+        int32_t x = 0xbe00001e;
+        sprintf( psz_cachename, "plugins-%.2x%.2x%.2x.dat", sizeof(int),
+                 sizeof(void *), (unsigned int)((unsigned char *)&x)[0] );
+        b_initialised = VLC_TRUE;
+    }
+
+    return psz_cachename;
+}
+
 /*****************************************************************************
  * CacheMerge: Merge a cache module descriptor with a full module descriptor.
  *****************************************************************************/