]> git.sesse.net Git - vlc/commitdiff
config_GetDataDirDefault(): return a heap-allocated string
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 13 Jan 2010 16:40:35 +0000 (18:40 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 13 Jan 2010 16:40:35 +0000 (18:40 +0200)
src/config/configuration.h
src/config/dirs.c
src/config/dirs_macos.c
src/config/dirs_xdg.c
src/libvlc.c
src/win32/dirs.c

index 2e88f9981cc62b44acd898011216e0fdce1e614d..d0b6e11cdecc42fa735ccc44572fd08025bad364 100644 (file)
@@ -45,7 +45,7 @@ void config_UnsetCallbacks( module_config_t *, size_t );
 int __config_LoadCmdLine   ( vlc_object_t *, int *, const char *[], bool );
 int __config_LoadConfigFile( vlc_object_t *, const char * );
 
-const char *config_GetDataDirDefault( void );
+char *config_GetDataDirDefault( void );
 
 int IsConfigStringType( int type );
 int IsConfigIntegerType (int type);
index d490975f5aefe596bf5d5b8338f66fcd2b31ba20..695b9455508dcc9781cac238ed6a21f79a54d34f 100644 (file)
@@ -33,7 +33,7 @@
 /**
  * Determines the shared data directory
  *
- * @return a string (always succeeds). Needs to be freed.
+ * @return a string or NULL. Use free() to release.
  */
 char *__config_GetDataDir( vlc_object_t *p_obj )
 {
@@ -41,6 +41,6 @@ char *__config_GetDataDir( vlc_object_t *p_obj )
     if( psz_path && *psz_path )
         return psz_path;
     free( psz_path );
-    return strdup( config_GetDataDirDefault() );
+    return config_GetDataDirDefault();
 }
 
index 7c00f022b5fe04d144a6f04920f670eea3d83b50..25fbd70d6bd5ed96747d86b9d6aa846c77fa5d5f 100644 (file)
 #include "configuration.h"
 
 static char *configdir = NULL;
-static char *datadir = NULL;
 
 static pthread_once_t once = PTHREAD_ONCE_INIT;
 
 static void init_dirs( void )
 {
     configdir = config_GetUserDir(VLC_CONFIG_DIR);
-    int ret = asprintf(&datadir, "%s/share", psz_vlcpath);
-    if (ret == -1)
-        datadir = NULL;
 }
 
 const char *config_GetConfDir( void )
@@ -54,9 +50,12 @@ const char *config_GetConfDir( void )
     return configdir;
 }
 
-const char *config_GetDataDirDefault (void)
+char *config_GetDataDirDefault (void)
 {
-    pthread_once(&once, init_dirs);
+    char *datadir;
+
+    if (asprintf (&datadir, "%s/share", psz_vlcpath) == -1)
+        return NULL;
     return datadir;
 }
 
index 7d8d9905047d18db8155a73adff5542f8bfba721..0f0d3e924c82916bec15406544727d2655dcdbfd 100644 (file)
 /**
  * Determines the shared data directory
  *
- * @return a string (always succeeds).
+ * @return a nul-terminated string or NULL. Use free() to release it.
  */
-const char *config_GetDataDirDefault( void )
+char *config_GetDataDirDefault (void)
 {
-    return DATA_PATH;
+    return strdup (DATA_PATH);
 }
 
 /**
index 81dacf921bcab3f1c2f684fe6e9c71076f500f11..0fdfc303703e25d7e436349ca8569bdacc239bba 100644 (file)
@@ -1224,11 +1224,16 @@ static inline int LoadMessages (void)
     static const char psz_path[] = LOCALEDIR;
 #else
     char psz_path[1024];
-    if (snprintf (psz_path, sizeof (psz_path), "%s" DIR_SEP "%s",
-                  config_GetDataDirDefault(), "locale")
-                     >= (int)sizeof (psz_path))
-        return -1;
+    char *datadir = config_GetDataDirDefault();
+    int ret;
 
+    if (unlikely(datadir == NULL))
+        return -1;
+    ret = snprintf (psz_path, sizeof (psz_path), "%s" DIR_SEP "locale",
+                    datadir);
+    free (datadir);
+    if (ret >= (int)sizeof (psz_path))
+        return -1;
 #endif
     if (bindtextdomain (PACKAGE_NAME, psz_path) == NULL)
     {
index 3a4909952f8cfb040af43beda5a1d1ff0198ed64..1053b3af9d72b344e594b649767ec1fc8ee8a6de 100644 (file)
 #include <assert.h>
 #include <limits.h>
 
-const char *config_GetDataDirDefault( void )
+char *config_GetDataDirDefault( void )
 {
-    static char path[PATH_MAX] = "";
-#warning FIXME: thread-safety!
-
-    if( *path == '\0' )
-        strlcpy (path, psz_vlcpath, sizeof (path));
-    return path;
+    return strdup (psz_vlcpath);
 }
 
 const char *config_GetConfDir (void)