From b987b2cc645c0b56ae0dd98b043ded476dcbdd1c Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 11 Jul 2015 03:27:17 +0200
Subject: degesch: add config_item_string_from_cstr()
---
common.c | 11 +++++++++++
degesch.c | 14 ++------------
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/common.c b/common.c
index 2020032..8f35896 100644
--- a/common.c
+++ b/common.c
@@ -1137,6 +1137,17 @@ config_item_string (const struct str *s)
return self;
}
+static struct config_item_ *
+config_item_string_from_cstr (const char *s)
+{
+ struct str tmp;
+ str_init (&tmp);
+ str_append (&tmp, s);
+ struct config_item_ *self = config_item_string (&tmp);
+ str_free (&tmp);
+ return self;
+}
+
static struct config_item_ *
config_item_string_array (const struct str *s)
{
diff --git a/degesch.c b/degesch.c
index 34a7975..86b9a0e 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1639,12 +1639,7 @@ set_config_string
struct config_item_ *item = config_item_get (root, key, NULL);
hard_assert (item);
- struct str s;
- str_init (&s);
- str_append (&s, value);
- struct config_item_ *new_ = config_item_string (&s);
- str_free (&s);
-
+ struct config_item_ *new_ = config_item_string_from_cstr (value);
struct error *e = NULL;
if (config_item_set_from (item, new_, &e))
return true;
@@ -8700,12 +8695,7 @@ load_default_aliases (struct app_context *ctx)
for (size_t i = 0; i < N_ELEMENTS (g_default_aliases); i++)
{
const char **pair = g_default_aliases[i];
-
- struct str tmp;
- str_init (&tmp);
- str_append (&tmp, pair[1]);
- str_map_set (aliases, pair[0], config_item_string (&tmp));
- str_free (&tmp);
+ str_map_set (aliases, pair[0], config_item_string_from_cstr (pair[1]));
}
}
--
cgit v1.2.3-70-g09d2