[vlc-devel] commit: config_GetDataDirDefault(): return a heap-allocated string ( Rémi Denis-Courmont )
git version control
git at videolan.org
Wed Jan 13 17:42:41 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jan 13 18:40:35 2010 +0200| [fcf05b24781d8a02b0172951d8b3b5b94bdefa38] | committer: Rémi Denis-Courmont
config_GetDataDirDefault(): return a heap-allocated string
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fcf05b24781d8a02b0172951d8b3b5b94bdefa38
---
src/config/configuration.h | 2 +-
src/config/dirs.c | 4 ++--
src/config/dirs_macos.c | 11 +++++------
src/config/dirs_xdg.c | 6 +++---
src/libvlc.c | 13 +++++++++----
src/win32/dirs.c | 9 ++-------
6 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/src/config/configuration.h b/src/config/configuration.h
index 2e88f99..d0b6e11 100644
--- a/src/config/configuration.h
+++ b/src/config/configuration.h
@@ -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);
diff --git a/src/config/dirs.c b/src/config/dirs.c
index d490975..695b945 100644
--- a/src/config/dirs.c
+++ b/src/config/dirs.c
@@ -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();
}
diff --git a/src/config/dirs_macos.c b/src/config/dirs_macos.c
index 7c00f02..25fbd70 100644
--- a/src/config/dirs_macos.c
+++ b/src/config/dirs_macos.c
@@ -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;
}
diff --git a/src/config/dirs_xdg.c b/src/config/dirs_xdg.c
index 7d8d990..0f0d3e9 100644
--- a/src/config/dirs_xdg.c
+++ b/src/config/dirs_xdg.c
@@ -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);
}
/**
diff --git a/src/libvlc.c b/src/libvlc.c
index 81dacf9..0fdfc30 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -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)
{
diff --git a/src/win32/dirs.c b/src/win32/dirs.c
index 3a49099..1053b3a 100644
--- a/src/win32/dirs.c
+++ b/src/win32/dirs.c
@@ -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)
More information about the vlc-devel
mailing list