Commit fcf05b24 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

config_GetDataDirDefault(): return a heap-allocated string

parent ee0fdf38
......@@ -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);
......
......@@ -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();
}
......@@ -36,16 +36,12 @@
#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;
}
......
......@@ -39,11 +39,11 @@
/**
* 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);
}
/**
......
......@@ -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)
{
......
......@@ -44,14 +44,9 @@
#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)
......
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