From: Florian Forster Date: Sun, 31 Oct 2010 11:39:10 +0000 (+0100) Subject: src/configfile.[ch]: Add "cf_util_get_cdtime". X-Git-Tag: collectd-5.0.0-beta0~19^2~21 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d6e55d065c568b599a9c27b2540c7e0233cf2318;p=collectd.git src/configfile.[ch]: Add "cf_util_get_cdtime". --- 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) */