From d6e55d065c568b599a9c27b2540c7e0233cf2318 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 31 Oct 2010 12:39:10 +0100 Subject: [PATCH] src/configfile.[ch]: Add "cf_util_get_cdtime". --- src/configfile.c | 25 +++++++++++++++++++++++++ src/configfile.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/configfile.c b/src/configfile.c index 99dded93..e162dd99 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -1059,3 +1059,28 @@ int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */ return (service_name_to_port_number (ci->values[0].value.string)); } /* }}} int cf_util_get_port_number */ + +int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */ +{ + if ((ci == NULL) || (ret_value == NULL)) + return (EINVAL); + + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) + { + ERROR ("cf_util_get_cdtime: The %s option requires " + "exactly one numeric argument.", ci->key); + return (-1); + } + + if (ci->values[0].value.number < 0.0) + { + ERROR ("cf_util_get_cdtime: The numeric argument of the %s " + "option must not be negative.", ci->key); + return (-1); + } + + *ret_value = DOUBLE_TO_CDTIME_T (ci->values[0].value.number); + + return (0); +} /* }}} int cf_util_get_cdtime */ + diff --git a/src/configfile.h b/src/configfile.h index 519a6ff8..65b1efcd 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -23,6 +23,7 @@ **/ #include "collectd.h" +#include "utils_time.h" #include "liboconfig/oconfig.h" /* @@ -113,4 +114,6 @@ int cf_util_get_flag (const oconfig_item_t *ci, * port number in the range [1-65535] or less than zero upon failure. */ int cf_util_get_port_number (const oconfig_item_t *ci); +int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value); + #endif /* defined(CONFIGFILE_H) */ -- 2.11.0