Commit 06acffbf authored by hpi1's avatar hpi1

Remove static variables from file_get_[cache|data|config]_home()

parent 882c5a46
......@@ -31,9 +31,10 @@ BD_PRIVATE char *win32_get_font_dir(const char *font_file);
* Config, cache and data dirs
*/
BD_PRIVATE const char *file_get_config_home(void);
BD_PRIVATE const char *file_get_config_system(const char *dir);
BD_PRIVATE const char *file_get_cache_home(void);
BD_PRIVATE const char *file_get_data_home(void);
BD_PRIVATE char *file_get_config_home(void);
BD_PRIVATE char *file_get_cache_home(void);
BD_PRIVATE char *file_get_data_home(void);
#endif
......@@ -38,61 +38,37 @@
#define SYSTEM_CFG_DIR "/Library/Preferences"
const char *file_get_config_home(void)
char *file_get_config_home(void)
{
static char *dir = NULL;
static int init_done = 0;
if (!init_done) {
init_done = 1;
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return dir = str_printf("%s/%s", user_home, USER_CFG_DIR);
}
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return str_printf("%s/%s", user_home, USER_CFG_DIR);
}
return dir;
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
return NULL;
}
const char *file_get_data_home(void)
char *file_get_data_home(void)
{
static char *dir = NULL;
static int init_done = 0;
if (!init_done) {
init_done = 1;
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return dir = str_printf("%s/%s", user_home, USER_DATA_DIR);
}
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return str_printf("%s/%s", user_home, USER_DATA_DIR);
}
return dir;
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
return NULL;
}
const char *file_get_cache_home(void)
char *file_get_cache_home(void)
{
static char *dir = NULL;
static int init_done = 0;
if (!init_done) {
init_done = 1;
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return dir = str_printf("%s/%s", user_home, USER_CACHE_DIR);
}
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return str_printf("%s/%s", user_home, USER_CACHE_DIR);
}
return dir;
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
return NULL;
}
const char *file_get_config_system(const char *dir)
......
......@@ -59,24 +59,20 @@ char *win32_get_font_dir(const char *font_file)
return path;
}
const char *file_get_config_home(void)
char *file_get_config_home(void)
{
return file_get_data_home();
}
const char *file_get_data_home(void)
char *file_get_data_home(void)
{
static char *appdir = NULL;
wchar_t wdir[MAX_PATH];
if (appdir)
return appdir;
/* Get the "Application Data" folder for the user */
if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, wdir)) {
int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
appdir = malloc(len);
char *appdir = malloc(len);
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
return appdir;
}
......@@ -85,7 +81,7 @@ const char *file_get_data_home(void)
return NULL;
}
const char *file_get_cache_home(void)
char *file_get_cache_home(void)
{
return file_get_data_home();
}
......
......@@ -41,76 +41,52 @@
#define SYSTEM_CFG_DIR "/etc/xdg"
const char *file_get_config_home(void)
char *file_get_config_home(void)
{
static char *dir = NULL;
static int init_done = 0;
if (!init_done) {
init_done = 1;
const char *xdg_home = getenv("XDG_CONFIG_HOME");
if (xdg_home && *xdg_home) {
return dir = str_printf("%s", xdg_home);
}
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return dir = str_printf("%s/%s", user_home, USER_CFG_DIR);
}
const char *xdg_home = getenv("XDG_CONFIG_HOME");
if (xdg_home && *xdg_home) {
return str_printf("%s", xdg_home);
}
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return str_printf("%s/%s", user_home, USER_CFG_DIR);
}
return dir;
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
return NULL;
}
const char *file_get_data_home(void)
char *file_get_data_home(void)
{
static char *dir = NULL;
static int init_done = 0;
if (!init_done) {
init_done = 1;
const char *xdg_home = getenv("XDG_DATA_HOME");
if (xdg_home && *xdg_home) {
return dir = str_printf("%s", xdg_home);
}
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return dir = str_printf("%s/%s", user_home, USER_DATA_DIR);
}
const char *xdg_home = getenv("XDG_DATA_HOME");
if (xdg_home && *xdg_home) {
return str_printf("%s", xdg_home);
}
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return str_printf("%s/%s", user_home, USER_DATA_DIR);
}
return dir;
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
return NULL;
}
const char *file_get_cache_home(void)
char *file_get_cache_home(void)
{
static char *dir = NULL;
static int init_done = 0;
if (!init_done) {
init_done = 1;
const char *xdg_cache = getenv("XDG_CACHE_HOME");
if (xdg_cache && *xdg_cache) {
return dir = str_printf("%s", xdg_cache);
}
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return dir = str_printf("%s/%s", user_home, USER_CACHE_DIR);
}
const char *xdg_cache = getenv("XDG_CACHE_HOME");
if (xdg_cache && *xdg_cache) {
return str_printf("%s", xdg_cache);
}
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
const char *user_home = getenv("HOME");
if (user_home && *user_home) {
return str_printf("%s/%s", user_home, USER_CACHE_DIR);
}
return dir;
BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n");
return NULL;
}
const char *file_get_config_system(const char *dir)
......
......@@ -264,6 +264,7 @@ static const char *_find_libbluray_jar(void)
static const char *_bdj_persistent_root(BDJ_STORAGE *storage)
{
const char *root;
char *data_home;
if (storage->persistent_root) {
return storage->persistent_root;
......@@ -274,11 +275,9 @@ static const char *_bdj_persistent_root(BDJ_STORAGE *storage)
return root;
}
root = file_get_data_home();
if (!root) {
root = "";
}
storage->persistent_root = str_printf("%s/bluray/dvb.persistent.root/", root);
data_home = file_get_data_home();
storage->persistent_root = str_printf("%s/bluray/dvb.persistent.root/", data_home ? data_home : "");
X_FREE(data_home);
BD_DEBUG(DBG_BDJ, "LIBBLURAY_PERSISTENT_ROOT not set, using %s\n", storage->persistent_root);
......@@ -288,6 +287,7 @@ static const char *_bdj_persistent_root(BDJ_STORAGE *storage)
static const char *_bdj_buda_root(BDJ_STORAGE *storage)
{
const char *root;
char *cache_home;
if (storage->cache_root) {
return storage->cache_root;
......@@ -298,11 +298,9 @@ static const char *_bdj_buda_root(BDJ_STORAGE *storage)
return root;
}
root = file_get_cache_home();
if (!root) {
root = "";
}
storage->cache_root = str_printf("%s/bluray/bluray.bindingunit.root/", root);
cache_home = file_get_cache_home();
storage->cache_root = str_printf("%s/bluray/bluray.bindingunit.root/", cache_home ? cache_home : "");
X_FREE(cache_home);
BD_DEBUG(DBG_BDJ, "LIBBLURAY_CACHE_ROOT not set, using %s\n", storage->cache_root);
......
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