summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-08-02 23:13:33 +0200
committerThomas Haller <thaller@redhat.com>2019-08-13 10:45:04 +0200
commitcc7b2cde95bb45072e51bdadd2d9760aec61fe58 (patch)
tree80fffa830a82039a4f3fdaaba2b747661216904e
parent1533a3e5d168186e672a08a37e395d70c89d7882 (diff)
downloadNetworkManager-cc7b2cde95bb45072e51bdadd2d9760aec61fe58.tar.gz
libnm: set errno in nm_key_file_get_boolean() to distinguish between missing key and error
This is also what nm_keyfile_plugin_kf_get_int64() does. It's useful to know whether a value was missing or invalid.
-rw-r--r--libnm-core/nm-keyfile-utils.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/libnm-core/nm-keyfile-utils.c b/libnm-core/nm-keyfile-utils.c
index 522d5b71fa..acc3458d85 100644
--- a/libnm-core/nm-keyfile-utils.c
+++ b/libnm-core/nm-keyfile-utils.c
@@ -49,18 +49,28 @@
* to detect parsing failures.
*
* Returns: either %TRUE or %FALSE if the key exists and is parsable as a boolean.
- * Otherwise, @default_value.
+ * Otherwise, @default_value. Sets errno to ENODATA, EINVAL or 0, depending on whether
+ * the key exists, whether the value is invalid, or success.
*/
int
nm_key_file_get_boolean (GKeyFile *kf, const char *group, const char *key, int default_value)
{
+ int v;
gs_free char *value = NULL;
value = g_key_file_get_value (kf, group, key, NULL);
- if (!value)
+ if (!value) {
+ errno = ENODATA;
return default_value;
- return _nm_utils_ascii_str_to_bool (value, default_value);
+ }
+ v = _nm_utils_ascii_str_to_bool (value, -1);
+ if (v != -1) {
+ errno = 0;
+ return v;
+ }
+ errno = EINVAL;
+ return default_value;
}
/*****************************************************************************/