aboutsummaryrefslogtreecommitdiffstats
path: root/common/name-value.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2022-08-11 08:55:00 +0000
committerWerner Koch <[email protected]>2022-08-11 09:25:49 +0000
commit40f0fcfaa476152088762cf5677770d3403d6055 (patch)
tree7e7d6d1b67f75ff385b08187ce6513855b53bd63 /common/name-value.c
parentgpg: Emit an ERROR status if --quick-set-primary-uid fails (diff)
downloadgnupg-40f0fcfaa476152088762cf5677770d3403d6055.tar.gz
gnupg-40f0fcfaa476152088762cf5677770d3403d6055.zip
common: New function nvc_get_boolean.
* common/name-value.c (nvc_get_boolean): New.
Diffstat (limited to 'common/name-value.c')
-rw-r--r--common/name-value.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/common/name-value.c b/common/name-value.c
index 39c3244e9..103c35d1c 100644
--- a/common/name-value.c
+++ b/common/name-value.c
@@ -597,6 +597,28 @@ nvc_get_string (nvc_t nvc, const char *name)
}
+/* Return true if NAME exists and its value is true; that is either
+ * "yes", "true", or a decimal value unequal to 0. */
+int
+nvc_get_boolean (nvc_t nvc, const char *name)
+{
+ nve_t item;
+ const char *s;
+
+ if (!nvc)
+ return 0;
+ item = nvc_lookup (nvc, name);
+ if (!item)
+ return 0;
+ s = nve_value (item);
+ if (s && (atoi (s)
+ || !ascii_strcasecmp (s, "yes")
+ || !ascii_strcasecmp (s, "true")))
+ return 1;
+ return 0;
+}
+
+
/* Private key handling. */