tree-wide: make use of path_extend() at many places
This is not a comprehensive port, but mostly some low-hanging fruit.
This commit is contained in:
+18
-21
@@ -36,35 +36,33 @@ int xdg_user_runtime_dir(char **ret, const char *suffix) {
|
||||
}
|
||||
|
||||
int xdg_user_config_dir(char **ret, const char *suffix) {
|
||||
_cleanup_free_ char *j = NULL;
|
||||
const char *e;
|
||||
char *j;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
e = getenv("XDG_CONFIG_HOME");
|
||||
if (e)
|
||||
if (e) {
|
||||
j = path_join(e, suffix);
|
||||
else {
|
||||
_cleanup_free_ char *home = NULL;
|
||||
|
||||
r = get_home_dir(&home);
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
} else {
|
||||
r = get_home_dir(&j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
j = path_join(home, "/.config", suffix);
|
||||
if (!path_extend(&j, "/.config", suffix))
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = j;
|
||||
*ret = TAKE_PTR(j);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xdg_user_data_dir(char **ret, const char *suffix) {
|
||||
_cleanup_free_ char *j = NULL;
|
||||
const char *e;
|
||||
char *j;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@@ -75,21 +73,20 @@ int xdg_user_data_dir(char **ret, const char *suffix) {
|
||||
* /etc/systemd/ anyway. */
|
||||
|
||||
e = getenv("XDG_DATA_HOME");
|
||||
if (e)
|
||||
if (e) {
|
||||
j = path_join(e, suffix);
|
||||
else {
|
||||
_cleanup_free_ char *home = NULL;
|
||||
|
||||
r = get_home_dir(&home);
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
} else {
|
||||
r = get_home_dir(&j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
j = path_join(home, "/.local/share", suffix);
|
||||
if (!path_extend(&j, "/.local/share", suffix))
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = j;
|
||||
*ret = TAKE_PTR(j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -681,7 +681,7 @@ int find_executable_full(const char *name, bool use_path_envvar, char **ret_file
|
||||
|
||||
/* Resolve a single-component name to a full path */
|
||||
for (;;) {
|
||||
_cleanup_free_ char *j = NULL, *element = NULL;
|
||||
_cleanup_free_ char *element = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
r = extract_first_word(&p, &element, ":", EXTRACT_RELAX|EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
@@ -693,11 +693,10 @@ int find_executable_full(const char *name, bool use_path_envvar, char **ret_file
|
||||
if (!path_is_absolute(element))
|
||||
continue;
|
||||
|
||||
j = path_join(element, name);
|
||||
if (!j)
|
||||
if (!path_extend(&element, name))
|
||||
return -ENOMEM;
|
||||
|
||||
r = check_x_access(j, ret_fd ? &fd : NULL);
|
||||
r = check_x_access(element, ret_fd ? &fd : NULL);
|
||||
if (r < 0) {
|
||||
/* PATH entries which we don't have access to are ignored, as per tradition. */
|
||||
if (r != -EACCES)
|
||||
@@ -707,7 +706,7 @@ int find_executable_full(const char *name, bool use_path_envvar, char **ret_file
|
||||
|
||||
/* Found it! */
|
||||
if (ret_filename)
|
||||
*ret_filename = path_simplify(TAKE_PTR(j), false);
|
||||
*ret_filename = path_simplify(TAKE_PTR(element), false);
|
||||
if (ret_fd)
|
||||
*ret_fd = TAKE_FD(fd);
|
||||
|
||||
|
||||
@@ -524,18 +524,17 @@ int mac_selinux_create_file_prepare_at(int dirfd, const char *path, mode_t mode)
|
||||
return 0;
|
||||
|
||||
if (!path_is_absolute(path)) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
if (dirfd == AT_FDCWD)
|
||||
r = safe_getcwd(&p);
|
||||
r = safe_getcwd(&abspath);
|
||||
else
|
||||
r = fd_get_path(dirfd, &p);
|
||||
r = fd_get_path(dirfd, &abspath);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
path = abspath = path_join(p, path);
|
||||
if (!path)
|
||||
if (!path_extend(&abspath, path))
|
||||
return -ENOMEM;
|
||||
|
||||
path = abspath;
|
||||
}
|
||||
|
||||
return selinux_create_file_prepare_abspath(path, mode);
|
||||
|
||||
@@ -123,13 +123,10 @@ int tempfn_xxxxxx(const char *p, const char *extra, char **ret) {
|
||||
return -EINVAL;
|
||||
|
||||
if (d) {
|
||||
char *j;
|
||||
|
||||
j = path_join(d, nf);
|
||||
if (!j)
|
||||
if (!path_extend(&d, nf))
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = path_simplify(j, false);
|
||||
*ret = path_simplify(TAKE_PTR(d), false);
|
||||
} else
|
||||
*ret = TAKE_PTR(nf);
|
||||
|
||||
@@ -168,13 +165,10 @@ int tempfn_random(const char *p, const char *extra, char **ret) {
|
||||
return -EINVAL;
|
||||
|
||||
if (d) {
|
||||
char *j;
|
||||
|
||||
j = path_join(d, nf);
|
||||
if (!j)
|
||||
if (!path_extend(&d, nf))
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = path_simplify(j, false);
|
||||
*ret = path_simplify(TAKE_PTR(d), false);
|
||||
} else
|
||||
*ret = TAKE_PTR(nf);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user