summaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-rw-r--r--support/include/conffile.h2
-rw-r--r--support/nfs/conffile.c32
2 files changed, 34 insertions, 0 deletions
diff --git a/support/include/conffile.h b/support/include/conffile.h
index a6d5846..3fe3a78 100644
--- a/support/include/conffile.h
+++ b/support/include/conffile.h
@@ -36,6 +36,7 @@
#include <sys/queue.h>
#include <ctype.h>
#include <stdint.h>
+#include <stdbool.h>
struct conf_list_node {
TAILQ_ENTRY(conf_list_node) link;
@@ -57,6 +58,7 @@ extern struct sockaddr *conf_get_address(char *, char *);
extern struct conf_list *conf_get_list(char *, char *);
extern struct conf_list *conf_get_tag_list(char *, char *);
extern int conf_get_num(char *, char *, int);
+extern _Bool conf_get_bool(char *, char *, _Bool);
extern char *conf_get_str(char *, char *);
extern char *conf_get_section(char *, char *, char *);
extern void conf_init(void);
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index 6b94ec0..609d782 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -446,6 +446,38 @@ conf_get_num(char *section, char *tag, int def)
return def;
}
+/*
+ * Return the Boolean value denoted by TAG in section SECTION, or DEF
+ * if that tags does not exist.
+ * FALSE is returned for case-insensitve comparisons with 0, f, false, n, no, off
+ * TRUE is returned for 1, t, true, y, yes, on
+ * A failure to match one of these results in DEF
+ */
+_Bool
+conf_get_bool(char *section, char *tag, _Bool def)
+{
+ char *value = conf_get_str(section, tag);
+
+ if (!value)
+ return def;
+ if (strcasecmp(value, "1") == 0 ||
+ strcasecmp(value, "t") == 0 ||
+ strcasecmp(value, "true") == 0 ||
+ strcasecmp(value, "y") == 0 ||
+ strcasecmp(value, "yes") == 0 ||
+ strcasecmp(value, "on") == 0)
+ return true;
+
+ if (strcasecmp(value, "0") == 0 ||
+ strcasecmp(value, "f") == 0 ||
+ strcasecmp(value, "false") == 0 ||
+ strcasecmp(value, "n") == 0 ||
+ strcasecmp(value, "no") == 0 ||
+ strcasecmp(value, "off") == 0)
+ return false;
+ return def;
+}
+
/* Validate X according to the range denoted by TAG in section SECTION. */
int
conf_match_num(char *section, char *tag, int x)