On Linux, this simplifies the code and improves relocability.
On Windows, OS/2 and MacOS, this should fix a small race condition.
VLC_API module_config_t * config_FindConfig( vlc_object_t *, const char * ) VLC_USED;
VLC_API char * config_GetDataDir( vlc_object_t * ) VLC_USED VLC_MALLOC;
#define config_GetDataDir(a) config_GetDataDir(VLC_OBJECT(a))
-VLC_API const char * config_GetLibDir( void ) VLC_USED;
+VLC_API char *config_GetLibDir(void) VLC_USED;
VLC_API const char * config_GetConfDir( void ) VLC_USED;
typedef enum vlc_userdir
free( datadir );
#if !(defined(__APPLE__) || defined(WIN32) || defined(__OS2__))
- if( likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s",
- config_GetLibDir(), luadirname ) != -1) )
+ char *psz_libpath = config_GetLibDir();
+ if( likely(psz_libpath != NULL) )
+ {
+ if( likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s",
+ psz_libpath, luadirname ) != -1) )
i++;
+ free( psz_libpath );
+ }
#endif
char *psz_datapath = config_GetDataDir( p_this );
/*
* To be cleaned-up module stuff:
*/
-extern char *psz_vlcpath;
-
module_t *module_find_by_shortcut (const char *psz_shortcut);
/**
return tab;
}
-char *psz_vlcpath = NULL;
-
#ifdef HAVE_DYNAMIC_PLUGINS
typedef enum { CACHE_USE, CACHE_RESET, CACHE_IGNORE } cache_mode_t;
*/
static void AllocateAllPlugins (vlc_object_t *p_this)
{
- const char *vlcpath = psz_vlcpath;
char *paths;
cache_mode_t mode;
/* Contruct the special search path for system that have a relocatable
* executable. Set it to <vlc path>/plugins. */
- assert( vlcpath );
-
- if( asprintf( &paths, "%s" DIR_SEP "plugins", vlcpath ) != -1 )
+ char *vlcpath = config_GetLibDir ();
+ if (likely(vlcpath != NULL)
+ && likely(asprintf (&paths, "%s" DIR_SEP "plugins", vlcpath) != -1))
{
AllocatePluginPath (p_this, paths, mode);
free( paths );
}
+ free (vlcpath);
/* If the user provided a plugin path, we add it to the list */
paths = getenv( "VLC_PLUGIN_PATH" );
#include <vlc_charset.h>
#include "config/configuration.h"
-static char *config_GetVlcDir (void)
+char *config_GetLibDir (void)
{
- return FromLocaleDup (psz_vlcpath);
+ HMODULE hmod;
+ CHAR psz_path[CCHMAXPATH + 4];
+
+ DosQueryModFromEIP( &hmod, NULL, 0, NULL, NULL, ( ULONG )system_Init );
+ DosQueryModuleName( hmod, sizeof( psz_path ), psz_path );
+
+ /* remove the DLL name */
+ char *slash = strrchr( psz_path, '\\');
+ if( slash == NULL )
+ abort();
+ strcpy(slash + 1, PACKAGE);
+ return FromLocaleDup(psz_path);
}
/**
*/
char *config_GetDataDirDefault (void)
{
- char *datadir = config_GetVlcDir();
+ char *datadir = config_GetLibDir();
if (datadir)
/* replace last lib\vlc with share */
return datadir;
}
-/**
- * Determines the architecture-dependent data directory
- *
- * @return a string (always succeeds).
- */
-const char *config_GetLibDir (void)
-{
- abort ();
-}
-
/**
* Determines the system configuration directory.
*
*/
const char *config_GetConfDir( void )
{
- return config_GetVlcDir ();
+#warning FIXME: memory leak
+ return config_GetLibDir ();
}
char *config_GetUserDir (vlc_userdir_t type)
case VLC_VIDEOS_DIR:
break;
}
- return config_GetVlcDir ();
+ return config_GetLibDir ();
}
void system_Init( void )
{
- HMODULE hmod;
- CHAR psz_path[ CCHMAXPATH ];
- PSZ psz_dirsep;
-
- DosQueryModFromEIP( &hmod, NULL, 0, NULL, NULL, ( ULONG )system_Init );
- DosQueryModuleName( hmod, sizeof( psz_path ), psz_path );
-
- /* remove the DLL name */
- psz_dirsep = strrchr( psz_path, '\\');
- if( psz_dirsep )
- *psz_dirsep = '\0';
-
- DosEnterCritSec();
-
- if( !psz_vlcpath )
- asprintf( &psz_vlcpath, "%s\\vlc", psz_path );
-
- DosExitCritSec();
-
/* Set the default file-translation mode */
_fmode_bin = 1;
setmode( fileno( stdin ), O_BINARY ); /* Needed for pipes */
void system_End( void )
{
- free( psz_vlcpath );
- psz_vlcpath = NULL;
}
* darwin_dirs.c: Mac OS X directories configuration
*****************************************************************************
* Copyright (C) 2001-2009 VLC authors and VideoLAN
- * Copyright © 2007-2009 Rémi Denis-Courmont
+ * Copyright © 2007-2012 Rémi Denis-Courmont
*
* Authors: Gildas Bazin <gbazin@videolan.org>
* Felix Paul Kühne <fkuehne at videolan dot org>
#include <vlc_configuration.h>
#include "config/configuration.h"
+#include <libgen.h>
+#include <dlfcn.h>
+#include <mach-o/dyld.h>
+
static char *configdir = NULL;
static pthread_once_t once = PTHREAD_ONCE_INIT;
return configdir;
}
-char *config_GetDataDirDefault (void)
+static char *config_GetLibPath (void)
{
- char *datadir;
+ /* Get the full program path and name */
+ /* First try to see if we are linked to the framework */
+ for (unsigned i = 0; i < _dyld_image_count(); i++)
+ {
+ const char *psz_img_name = _dyld_get_image_name(i);
+ const char *p = strstr( psz_img_name, "VLCKit.framework/Versions/" );
- if (asprintf (&datadir, "%s/share", psz_vlcpath) == -1)
- return NULL;
- return datadir;
+ /* Check for "VLCKit.framework/Versions/Current/VLCKit",
+ * as well as "VLCKit.framework/Versions/A/VLCKit" and
+ * "VLC.framework/Versions/B/VLCKit" */
+ if( p != NULL )
+ {
+ /* Look for the next forward slash */
+ p += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
+ p += strcspn( p, "/" );
+
+ /* If the string ends with VLC then we've found a winner */
+ if ( !strcmp( p, "/VLCKit" ) )
+ return strdup( psz_img_name );
+ }
+
+ /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't
+ * link to VLCKit. */
+ size_t len = strlen(psz_img_name);
+ if( len >= 3 && !strcmp( psz_img_name + len - 3, "VLC") )
+ return strdup( psz_img_name );
+ }
+
+ /* We are not linked to the VLC.framework, let's use dladdr to figure
+ * libvlc path */
+ Dl_info info;
+ if( dladdr(system_Init, &info) )
+ return strdup(dirname( info.dli_fname ));
+
+ char path[MAXPATHLEN+1];
+ uint32_t path_len = sizeof(path) - 1;
+
+ if ( !_NSGetExecutablePath(path, &path_len) )
+ return strdup(path);
+ return NULL;
}
-const char *config_GetLibDir (void)
+char *config_GetLibDir (void)
{
+ char *path = config_GetLibPath ();
+ if (path != NULL)
+ {
+ char *p = strrchr (p, '/');
+ if (p != NULL)
+ {
+ *p = '\0';
+ return path;
+ }
+ free (path);
+ }
+
+ /* should never happen */
abort ();
}
+char *config_GetDataDirDefault (void)
+{
+ char *vlcpath = config_GetLibDir ();
+ char *datadir;
+
+ if (asprintf (&datadir, "%s/share", vlcpath) == -1)
+ datadir = NULL;
+
+ free (vlcpath);
+ return datadir;
+}
+
static char *config_GetHomeDir (void)
{
const char *home = getenv ("HOME");
#include <vlc_common.h>
#include "../libvlc.h"
#include <dirent.h> /* *dir() */
-#include <libgen.h>
-#include <dlfcn.h>
#include <CoreFoundation/CoreFoundation.h>
-#include <mach-o/dyld.h>
#ifdef HAVE_LOCALE_H
# include <locale.h>
*****************************************************************************/
void system_Init(void)
{
- char i_dummy;
- char *p_char = NULL;
- char *p_oldchar = &i_dummy;
- unsigned int i;
-
- /* Get the full program path and name */
- /* First try to see if we are linked to the framework */
- for (i = 0; i < _dyld_image_count(); i++)
- {
- const char * psz_img_name = _dyld_get_image_name(i);
- /* Check for "VLCKit.framework/Versions/Current/VLCKit",
- * as well as "VLCKit.framework/Versions/A/VLCKit" and
- * "VLC.framework/Versions/B/VLCKit" */
- if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) )
- {
- /* Look for the next forward slash */
- p_char += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
- while( *p_char != '\0' && *p_char != '/')
- p_char++;
-
- /* If the string ends with VLC then we've found a winner */
- if ( !strcmp( p_char, "/VLCKit" ) )
- {
- p_char = strdup( psz_img_name );
- break;
- }
- else
- p_char = NULL;
- }
- else
- {
- size_t len = strlen(psz_img_name);
- /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't
- * link to VLCKit. */
- if( !strcmp( psz_img_name + len - 3, "VLC") )
- {
- p_char = strdup( psz_img_name );
- break;
- }
- }
- }
- if ( !p_char )
- {
- /* We are not linked to the VLC.framework, let's use dladdr to figure
- * libvlc path */
- Dl_info info;
- if( dladdr(system_Init, &info) )
- p_char = strdup(dirname( info.dli_fname ));
- }
- if( !p_char )
- {
- char path[MAXPATHLEN+1];
- uint32_t path_len = MAXPATHLEN;
- if ( !_NSGetExecutablePath(path, &path_len) )
- p_char = strdup(path);
- }
-
- free(psz_vlcpath);
- psz_vlcpath = p_char;
-
- /* Remove trailing program name */
- for( ; *p_char ; )
- {
- if( *p_char == '/' )
- {
- *p_oldchar = '/';
- *p_char = '\0';
- p_oldchar = p_char;
- }
- p_char++;
- }
-
#ifdef ENABLE_NLS
/* Check if $LANG is set. */
if( NULL == getenv("LANG") )
*****************************************************************************/
void system_End( void )
{
- free( psz_vlcpath );
- psz_vlcpath = NULL;
}
return strdup (DATA_PATH);
}
+#if !defined (__linux__)
/**
* Determines the architecture-dependent data directory
*
* @return a string (always succeeds).
*/
-const char *config_GetLibDir (void)
+char *config_GetLibDir (void)
{
- return PKGLIBDIR;
+ return strdup (PKGLIBDIR);
}
+#endif
/**
* Determines the system configuration directory.
/*****************************************************************************
* linux_specific.c: Linux-specific initialization
*****************************************************************************
- * Copyright © 2008 Rémi Denis-Courmont
+ * Copyright © 2008-2012 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
#include <vlc_common.h>
#include "../libvlc.h"
-static const char default_path[] = PKGLIBDIR;
-
-static void set_libvlc_path (void)
+char *config_GetLibDir (void)
{
+ char *path = NULL;
+
/* Find the path to libvlc (i.e. ourselves) */
FILE *maps = fopen ("/proc/self/maps", "rt");
if (maps == NULL)
char *line = NULL;
size_t linelen = 0;
- uintptr_t needle = (uintptr_t)set_libvlc_path;
+ uintptr_t needle = (uintptr_t)config_GetLibDir;
for (;;)
{
void *start, *end;
if (sscanf (line, "%p-%p", &start, &end) < 2)
continue;
+ /* This mapping contains the address of this function. */
if (needle < (uintptr_t)start || (uintptr_t)end <= needle)
continue;
+
char *dir = strchr (line, '/');
if (dir == NULL)
continue;
+
char *file = strrchr (line, '/');
if (end == NULL)
continue;
*file = '\0';
- if (asprintf (&psz_vlcpath, "%s/"PACKAGE, dir) == -1)
- goto error;
+
+ if (asprintf (&path, "%s/"PACKAGE, dir) == -1)
+ path = NULL;
break;
}
+
free (line);
fclose (maps);
- return;
-
error:
- psz_vlcpath = (char *)default_path; /* default, cannot fail */
+ return (path != NULL) ? path : strdup (PKGLIBDIR);
}
-static void unset_libvlc_path (void)
-{
- if (psz_vlcpath != default_path)
- free (psz_vlcpath);
-}
-
-static struct
-{
- vlc_mutex_t lock;
- unsigned refs;
-} once = { VLC_STATIC_MUTEX, 0 };
-
#ifdef __GLIBC__
# include <gnu/libc-version.h>
# include <stdlib.h>
fflush (stderr);
}
#endif
-
- vlc_mutex_lock (&once.lock);
- if (once.refs++ == 0)
- set_libvlc_path ();
- vlc_mutex_unlock (&once.lock);
}
void system_Configure (libvlc_int_t *libvlc,
void system_End (void)
{
- vlc_mutex_lock (&once.lock);
- if (--once.refs == 0)
- unset_libvlc_path ();
- vlc_mutex_unlock (&once.lock);
}
#include <vlc_common.h>
#include "../libvlc.h"
-#include <pthread.h>
-
-static void set_libvlc_path (void)
-{
- psz_vlcpath = (char *)PKGLIBDIR;
-}
void system_Init (void)
{
- pthread_once_t once = PTHREAD_ONCE_INIT;
-
- pthread_once (&once, set_libvlc_path);
}
void system_Configure (libvlc_int_t *libvlc,
/*****************************************************************************
* dirs.c: directories configuration
*****************************************************************************
- * Copyright (C) 2001-2007 VLC authors and VideoLAN
- * Copyright © 2007-2008 Rémi Denis-Courmont
+ * Copyright (C) 2001-2010 VLC authors and VideoLAN
+ * Copyright © 2007-2012 Rémi Denis-Courmont
*
* Authors: Gildas Bazin <gbazin@videolan.org>
*
# include "config.h"
#endif
+#define UNICODE
#include <vlc_common.h>
#include <w32api.h>
#include <assert.h>
#include <limits.h>
-char *config_GetDataDirDefault( void )
+char *config_GetLibDir (void)
{
- return strdup (psz_vlcpath);
+ /* Get our full path */
+ MEMORY_BASIC_INFORMATION mbi;
+ if (!VirtualQuery (config_GetLibDir, &mbi, sizeof(mbi)))
+ goto error;
+
+ wchar_t wpath[MAX_PATH];
+ if (!GetModuleFileName ((HMODULE) mbi.AllocationBase, wpath, MAX_PATH))
+ goto error;
+
+ wchar_t *file = wcsrchr (wpath, L'\\');
+ if (file == NULL)
+ goto error;
+ *file = L'\0';
+
+ return FromWide (wpath);
+error:
+ abort ();
}
-const char *config_GetLibDir (void)
+char *config_GetDataDirDefault( void )
{
- abort ();
+ return config_GetLibDir ();
}
const char *config_GetConfDir (void)
void system_Init( void )
{
WSADATA Data;
- MEMORY_BASIC_INFORMATION mbi;
-
- /* Get our full path */
- char psz_path[MAX_PATH];
- char *psz_vlc;
-
- wchar_t psz_wpath[MAX_PATH];
- if( VirtualQuery(system_Init, &mbi, sizeof(mbi) ) )
- {
- HMODULE hMod = (HMODULE) mbi.AllocationBase;
- if( GetModuleFileName( hMod, psz_wpath, MAX_PATH ) )
- {
- WideCharToMultiByte( CP_UTF8, 0, psz_wpath, -1,
- psz_path, MAX_PATH, NULL, NULL );
- }
- else psz_path[0] = '\0';
- }
- else psz_path[0] = '\0';
-
- psz_vlc = strrchr( psz_path, '\\' );
- if( psz_vlc )
- *psz_vlc = '\0';
-
- {
- /* remove trailing \.libs from executable dir path if seen,
- we assume we are running vlc through libtool wrapper in build dir */
- size_t len = strlen(psz_path);
- if( len >= 5 && !stricmp(psz_path + len - 5, "\\.libs" ) )
- psz_path[len - 5] = '\0';
- }
-
- psz_vlcpath = strdup( psz_path );
#if !defined( UNDER_CE )
timeBeginPeriod(5);
{
HWND ipcwindow;
- free( psz_vlcpath );
- psz_vlcpath = NULL;
-
/* FIXME: thread-safety... */
if (p_helper)
{