diff options
author | NeilBrown <neilb@suse.com> | 2016-12-06 12:44:12 -0500 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2016-12-20 13:29:04 -0500 |
commit | 2d230e3e762e9ff543b4d037696a79ff9c328dcf (patch) | |
tree | 95e95bf163c3bc106b102c1507ecd3ee0db9ba94 /support/nfs/conffile.c | |
parent | 0cc5c137baad73613441b7475f1e0873e2a5dcc3 (diff) | |
download | nfs-utils-2d230e3e762e9ff543b4d037696a79ff9c328dcf.tar.gz nfs-utils-2d230e3e762e9ff543b4d037696a79ff9c328dcf.tar.xz nfs-utils-2d230e3e762e9ff543b4d037696a79ff9c328dcf.zip |
conffile: add bool support
conf_get_bool() interprets various strings as 'true' or 'false'.
If no suitable value is found, the default is returned.
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/nfs/conffile.c')
-rw-r--r-- | support/nfs/conffile.c | 32 |
1 files changed, 32 insertions, 0 deletions
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) |