aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2024-02-08 17:05:22 +0100
committerSimon Zeni <simon@bl4ckb0ne.ca>2024-02-08 16:11:24 -0500
commit88b2abf5f208422ffc503c2c1d2a0de95d9ec4c5 (patch)
treef4cbaf307815a8cc1918728905bbb44f5c0fe0fa
parent93d391651c1ad43eb8b54449769e034eb1f2380c (diff)
config: use format_str() instead of hand-rolled snprintf()
-rw-r--r--sway/config.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/sway/config.c b/sway/config.c
index d7b6b693..e91c0c8b 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -352,13 +352,7 @@ static char *config_path(const char *prefix, const char *config_folder) {
if (!prefix || !prefix[0] || !config_folder || !config_folder[0]) {
return NULL;
}
-
- const char *filename = "config";
-
- size_t size = 3 + strlen(prefix) + strlen(config_folder) + strlen(filename);
- char *path = calloc(size, sizeof(char));
- snprintf(path, size, "%s/%s/%s", prefix, config_folder, filename);
- return path;
+ return format_str("%s/%s/config", prefix, config_folder);
}
static char *get_config_path(void) {
@@ -368,10 +362,7 @@ static char *get_config_path(void) {
const char *config_home = getenv("XDG_CONFIG_HOME");
if ((config_home == NULL || config_home[0] == '\0') && home != NULL) {
- size_t size_fallback = 1 + strlen(home) + strlen("/.config");
- config_home_fallback = calloc(size_fallback, sizeof(char));
- if (config_home_fallback != NULL)
- snprintf(config_home_fallback, size_fallback, "%s/.config", home);
+ config_home_fallback = format_str("%s/.config", home);
config_home = config_home_fallback;
}