mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
core-util: Add pa_get_config_home_dir()
This commit is contained in:
parent
14845b2c8e
commit
6c5c65a718
2 changed files with 27 additions and 18 deletions
|
|
@ -1549,16 +1549,6 @@ int pa_unlock_lockfile(const char *fn, int fd) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_config_home(char *home) {
|
|
||||||
char *t;
|
|
||||||
|
|
||||||
t = getenv("XDG_CONFIG_HOME");
|
|
||||||
if (t)
|
|
||||||
return pa_xstrdup(t);
|
|
||||||
|
|
||||||
return pa_sprintf_malloc("%s" PA_PATH_SEP ".config", home);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int check_ours(const char *p) {
|
static int check_ours(const char *p) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
|
@ -1576,7 +1566,7 @@ static int check_ours(const char *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_pulse_home(void) {
|
static char *get_pulse_home(void) {
|
||||||
char *h, *ret, *config_home;
|
char *h, *ret;
|
||||||
int t;
|
int t;
|
||||||
|
|
||||||
h = pa_get_home_dir_malloc();
|
h = pa_get_home_dir_malloc();
|
||||||
|
|
@ -1594,17 +1584,14 @@ static char *get_pulse_home(void) {
|
||||||
|
|
||||||
/* If the old directory exists, use it. */
|
/* If the old directory exists, use it. */
|
||||||
ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
|
ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
|
||||||
if (access(ret, F_OK) >= 0) {
|
pa_xfree(h);
|
||||||
free(h);
|
if (access(ret, F_OK) >= 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
free(ret);
|
free(ret);
|
||||||
|
|
||||||
/* Otherwise go for the XDG compliant directory. */
|
/* Otherwise go for the XDG compliant directory. */
|
||||||
config_home = get_config_home(h);
|
if (pa_get_config_home_dir(&ret) < 0)
|
||||||
free(h);
|
return NULL;
|
||||||
ret = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse", config_home);
|
|
||||||
free(config_home);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -1670,6 +1657,27 @@ int pa_append_to_home_dir(const char *path, char **_r) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pa_get_config_home_dir(char **_r) {
|
||||||
|
const char *e;
|
||||||
|
char *home_dir;
|
||||||
|
|
||||||
|
pa_assert(_r);
|
||||||
|
|
||||||
|
e = getenv("XDG_CONFIG_HOME");
|
||||||
|
if (e && *e) {
|
||||||
|
*_r = pa_sprintf_malloc("%s" PA_PATH_SEP "pulse", e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
home_dir = pa_get_home_dir_malloc();
|
||||||
|
if (!home_dir)
|
||||||
|
return -PA_ERR_NOENTITY;
|
||||||
|
|
||||||
|
*_r = pa_sprintf_malloc("%s" PA_PATH_SEP ".config" PA_PATH_SEP "pulse", home_dir);
|
||||||
|
pa_xfree(home_dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char *pa_get_binary_name_malloc(void) {
|
char *pa_get_binary_name_malloc(void) {
|
||||||
char *t;
|
char *t;
|
||||||
size_t allocated = 128;
|
size_t allocated = 128;
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ char *pa_get_runtime_dir(void);
|
||||||
char *pa_get_state_dir(void);
|
char *pa_get_state_dir(void);
|
||||||
char *pa_get_home_dir_malloc(void);
|
char *pa_get_home_dir_malloc(void);
|
||||||
int pa_append_to_home_dir(const char *path, char **_r);
|
int pa_append_to_home_dir(const char *path, char **_r);
|
||||||
|
int pa_get_config_home_dir(char **_r);
|
||||||
char *pa_get_binary_name_malloc(void);
|
char *pa_get_binary_name_malloc(void);
|
||||||
char *pa_runtime_path(const char *fn);
|
char *pa_runtime_path(const char *fn);
|
||||||
char *pa_state_path(const char *fn, bool prepend_machine_id);
|
char *pa_state_path(const char *fn, bool prepend_machine_id);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue