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);
/**
* 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 )
{
if( psz_path && *psz_path )
return psz_path;
free( psz_path );
- return strdup( config_GetDataDirDefault() );
+ return config_GetDataDirDefault();
}
#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 )
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;
}
/**
* 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);
}
/**
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)
{
#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)