xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3()

This avoids the need for an unused third argument for most xstrjoin()
calls and replaces the cases where it's needed with a more flexible
function. Code generation is the same in both cases, when there are 2
string params and a compile-time known delimiter.

This commit also converts 4 uses of xasprintf() to use xstrjoin*().

See also: https://godbolt.org/z/xsjrhv9b6
This commit is contained in:
Craig Barnes 2024-08-03 08:12:13 +01:00
parent 62b0b65d47
commit f87c9bb9f7
7 changed files with 44 additions and 31 deletions

View file

@ -356,9 +356,9 @@ open_config(void)
/* First, check XDG_CONFIG_HOME (or .config, if unset) */
if (xdg_config_home != NULL && xdg_config_home[0] != '\0')
path = xstrjoin(xdg_config_home, "/foot/foot.ini", 0);
path = xstrjoin(xdg_config_home, "/foot/foot.ini");
else if (home_dir != NULL)
path = xstrjoin(home_dir, "/.config/foot/foot.ini", 0);
path = xstrjoin(home_dir, "/.config/foot/foot.ini");
if (path != NULL) {
LOG_DBG("checking for %s", path);
@ -383,7 +383,7 @@ open_config(void)
conf_dir = strtok(NULL, ":"))
{
free(path);
path = xstrjoin(conf_dir, "/foot/foot.ini", 0);
path = xstrjoin(conf_dir, "/foot/foot.ini");
LOG_DBG("checking for %s", path);
int fd = open(path, O_RDONLY | O_CLOEXEC);
@ -843,7 +843,7 @@ parse_section_main(struct context *ctx)
return false;
}
_include_path = xasprintf("%s/%s", home_dir, value + 2);
_include_path = xstrjoin3(home_dir, "/", value + 2);
include_path = _include_path;
} else
include_path = value;
@ -2931,7 +2931,7 @@ get_server_socket_path(void)
const char *wayland_display = getenv("WAYLAND_DISPLAY");
if (wayland_display == NULL) {
return xstrjoin(xdg_runtime, "/foot.sock", 0);
return xstrjoin(xdg_runtime, "/foot.sock");
}
return xasprintf("%s/foot-%s.sock", xdg_runtime, wayland_display);