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

posix: merge Linux config_GetDataDir()

There are no needs to distinguish Linux for standard here.
Also make config_GetDataDir() static.
parent 1beb944f
......@@ -55,30 +55,12 @@ extern bool config_dirty;
bool config_IsSafe (const char *);
/**
* Gets the arch-independent installation directory.
*
* This function determines the directory containing the
* architecture-independent installed asset files (such as image, text and
* message translation tables).
*
* See also config_GetLibDir().
*
* @return a heap-allocated string (use free() to release it), or NULL on error
*/
char *config_GetDataDir(void) VLC_USED VLC_MALLOC;
/**
* Gets the arch-specific installation directory.
*
* This function determines the directory containing the architecture-specific
* installed asset files (such as executable plugins and compiled byte code).
*
* See also config_GetDataDir().
*
* \note config_GetDataDir() and config_GetLibDir() may or may not return the
* same path, depending on conventions of the operating system.
*
* @return a heap-allocated string (use free() to release it), or NULL on error
*/
char *config_GetLibDir(void) VLC_USED VLC_MALLOC;
......
......@@ -92,7 +92,7 @@ char *config_GetLibDir (void)
abort ();
}
char *config_GetDataDir (void)
static char *config_GetDataDir(void)
{
const char *path = getenv ("VLC_DATA_PATH");
if (path)
......
......@@ -100,35 +100,3 @@ char *config_GetLibDir(void)
pthread_once(&once, config_GetLibDirOnce);
return strdup(cached_path);
}
char *config_GetDataDir (void)
{
const char *path = getenv ("VLC_DATA_PATH");
if (path != NULL)
return strdup (path);
char *libdir = config_GetLibDir ();
if (libdir == NULL)
return NULL; /* OOM */
/* Look for common prefix between lib and data directories. */
size_t prefix_len = 0;
while (PKGLIBDIR[prefix_len] == PKGDATADIR[prefix_len])
{
if (PKGLIBDIR[prefix_len] == '\0')
return libdir; /* corner case: directories are identical */
prefix_len++;
}
char *datadir = NULL;
char *p = strstr(libdir, PKGLIBDIR + prefix_len);
if (p != NULL)
{
if (unlikely(asprintf(&datadir, "%.*s%s", (int)(p - libdir), libdir,
PKGDATADIR + prefix_len) == -1))
datadir = NULL;
}
free (libdir);
return (datadir != NULL) ? datadir : strdup (PKGDATADIR);
}
......@@ -51,7 +51,7 @@ char *config_GetLibDir (void)
*
* @return a nul-terminated string or NULL. Use free() to release it.
*/
char *config_GetDataDir (void)
static char *config_GetDataDir(void)
{
const char *path = getenv ("VLC_DATA_PATH");
if (path)
......
......@@ -36,25 +36,51 @@
#include <limits.h>
/**
* Determines the shared data directory
* Determines the architecture-dependent data directory
*
* @return a nul-terminated string or NULL. Use free() to release it.
* @return a string (always succeeds).
*/
VLC_WEAK char *config_GetDataDir(void)
VLC_WEAK char *config_GetLibDir(void)
{
const char *path = getenv ("VLC_DATA_PATH");
return strdup ((path != NULL) ? path : PKGDATADIR);
const char *path = getenv("VLC_LIB_PATH");
return strdup((path != NULL) ? path : PKGLIBDIR);
}
/**
* Determines the architecture-dependent data directory
* Determines the shared data directory
*
* @return a string (always succeeds).
* @return a nul-terminated string or NULL. Use free() to release it.
*/
VLC_WEAK char *config_GetLibDir(void)
static char *config_GetDataDir(void)
{
const char *path = getenv("VLC_LIB_PATH");
return strdup((path != NULL) ? path : PKGLIBDIR);
const char *path = getenv("VLC_DATA_PATH");
if (path != NULL)
return strdup(path);
char *libdir = config_GetLibDir();
if (libdir == NULL)
return NULL; /* OOM */
/* Look for common prefix between lib and data directories. */
size_t prefix_len = 0;
while (PKGLIBDIR[prefix_len] == PKGDATADIR[prefix_len])
{
if (PKGLIBDIR[prefix_len] == '\0')
return libdir; /* corner case: directories are identical */
prefix_len++;
}
char *datadir = NULL;
char *p = strstr(libdir, PKGLIBDIR + prefix_len);
if (p != NULL)
{
if (unlikely(asprintf(&datadir, "%.*s%s", (int)(p - libdir), libdir,
PKGDATADIR + prefix_len) == -1))
datadir = NULL;
}
free (libdir);
return (datadir != NULL) ? datadir : strdup (PKGDATADIR);
}
char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
......
......@@ -206,7 +206,7 @@ error:
#endif
}
char *config_GetDataDir (void)
static char *config_GetDataDir(void)
{
const char *path = getenv ("VLC_DATA_PATH");
return (path != NULL) ? strdup (path) : config_GetLibDir ();
......
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