From: RĂ©mi Denis-Courmont Date: Wed, 13 Jan 2010 16:40:35 +0000 (+0200) Subject: config_GetDataDirDefault(): return a heap-allocated string X-Git-Tag: 1.1.0-ff~1253 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=fcf05b24781d8a02b0172951d8b3b5b94bdefa38;p=vlc config_GetDataDirDefault(): return a heap-allocated string --- diff --git a/src/config/configuration.h b/src/config/configuration.h index 2e88f9981c..d0b6e11cde 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 d490975f5a..695b945550 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 7c00f022b5..25fbd70d6b 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 7d8d990504..0f0d3e924c 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 81dacf921b..0fdfc30370 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 3a4909952f..1053b3af9d 100644 --- a/src/win32/dirs.c +++ b/src/win32/dirs.c @@ -44,14 +44,9 @@ #include #include -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)