summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0276fb2)
raw | patch | inline | side by side (parent: 0276fb2)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 13 Jun 2010 13:25:31 +0000 (15:25 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 13 Jun 2010 13:25:51 +0000 (15:25 +0200) |
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index afc3e479a7d237603d9bb756f5b2262f83ea1adf..46624dc96ce6ac7b4bd9b4fa827db014b6e041fa 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
/**
* collectd - src/configfile.c
- * Copyright (C) 2005-2009 Florian octo Forster
+ * Copyright (C) 2005-2010 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -1009,11 +1009,37 @@ int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
return (-1);
}
- *ret_bool = ci->values[0].value.boolean ? true : false;
+ *ret_bool = ci->values[0].value.boolean ? 1 : 0;
return (0);
} /* }}} int cf_util_get_boolean */
+int cf_util_get_flag (const oconfig_item_t *ci, /* {{{ */
+ unsigned int *ret_value, unsigned int flag)
+{
+ int status;
+ _Bool b;
+
+ if (ret_value == NULL)
+ return (EINVAL);
+
+ b = 0;
+ status = cf_util_get_boolean (ci, &b);
+ if (status != 0)
+ return (status);
+
+ if (b)
+ {
+ *ret_value |= flag;
+ }
+ else
+ {
+ *ret_value &= ~flag;
+ }
+
+ return (0);
+} /* }}} int cf_util_get_flag */
+
/* Assures that the config option is a string. The string is then converted to
* a port number using `service_name_to_port_number' and returned. Returns the
* port number in the range [1-65535] or less than zero upon failure. */
diff --git a/src/configfile.h b/src/configfile.h
index 432e09f5ba73f0663669dfe0f6bae7f65e154f48..519a6ff8668668b6f6c6deef72c60041de27a329 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
#define CONFIGFILE_H
/**
* collectd - src/configfile.h
- * Copyright (C) 2005,2006 Florian octo Forster
+ * Copyright (C) 2005-2010 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Otherwise, `ret_bool' is not changed and non-zero is returned. */
int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
+/* Assures the config option is a boolean and set or unset the given flag in
+ * `ret_value' as appropriate. Returns non-zero on error. */
+int cf_util_get_flag (const oconfig_item_t *ci,
+ unsigned int *ret_value, unsigned int flag);
+
/* Assures that the config option is a string. The string is then converted to
* a port number using `service_name_to_port_number' and returned. Returns the
* port number in the range [1-65535] or less than zero upon failure. */