From b03b5694bc752d9cb75dada2f53edf4f9e78e2fb Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 16 Feb 2012 11:58:53 +0100 Subject: src/config.c: Introduce config_parse_str() Be consistent with other parser helpers and with config_serialize_str(). Signed-off-by: Lukas Fleischer --- src/config.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index f744b67..8b7accf 100644 --- a/src/config.c +++ b/src/config.c @@ -77,6 +77,13 @@ config_parse_int (int *dest, const char *val) return 1; } +static int +config_parse_str (char *dest, const char *val) +{ + strncpy (dest, val, BUFSIZ); + return 1; +} + static int config_parse_color (int *dest, const char *val) { @@ -183,30 +190,24 @@ config_set_conf (const char *key, const char *value) if (!strcmp(key, "notify-bar_show")) return config_parse_bool (&nbar.show, value); - if (!strcmp(key, "notify-bar_date")) { - strncpy (nbar.datefmt, value, strlen (value) + 1); - return 1; - } + if (!strcmp(key, "notify-bar_date")) + return config_parse_str (nbar.datefmt, value); - if (!strcmp(key, "notify-bar_clock")) { - strncpy (nbar.timefmt, value, strlen (value) + 1); - return 1; - } + if (!strcmp(key, "notify-bar_clock")) + return config_parse_str (nbar.timefmt, value); if (!strcmp(key, "notify-bar_warning")) return config_parse_int (&nbar.cntdwn, value); - if (!strcmp(key, "notify-bar_command")) { - strncpy (nbar.cmd, value, strlen (value) + 1); - return 1; - } + if (!strcmp(key, "notify-bar_command")) + return config_parse_str (nbar.cmd, value); if (!strcmp(key, "notify-all")) return config_parse_bool(&nbar.notify_all, value); if (!strcmp(key, "output_datefmt")) { if (value[0] != '\0') - strncpy (conf.output_datefmt, value, strlen (value) + 1); + return config_parse_str (conf.output_datefmt, value); return 1; } -- cgit v1.2.3-54-g00ecf