}
/**
- * g_key_file_has_key:
+ * g_key_file_has_key: (skip)
* @key_file: a #GKeyFile
* @group_name: a group name
* @key: a key name
* @error: return location for a #GError
*
* Looks whether the key file has the key @key in the group
- * @group_name.
+ * @group_name.
+ *
+ * <note>This function does not follow the rules for #GError strictly;
+ * the return value both carries meaning and signals an error. To use
+ * this function, you must pass a #GError pointer in @error, and check
+ * whether it is not %NULL to see if an error occurred.</note>
+ *
+ * See g_key_file_has_key_full() for a replacement function which does
+ * follow the #GError rules.
*
* Return value: %TRUE if @key is a part of @group_name, %FALSE
* otherwise.
const gchar *key,
GError **error)
{
+ GError *temp_error = NULL;
+ gboolean has_key;
+
+ if (g_key_file_has_key_full (key_file, group_name, key, &has_key, &temp_error))
+ {
+ return has_key;
+ }
+ else
+ {
+ g_propagate_error (error, temp_error);
+ return FALSE;
+ }
+}
+
+/**
+ * g_key_file_has_key_full:
+ * @key_file: a #GKeyFile
+ * @group_name: a group name
+ * @key: a key name
+ * @has_key: (out) (allow-none): Return location for whether or not key exists
+ * @error: return location for a #GError
+ *
+ * Looks whether the key file has the key @key in the group
+ * @group_name.
+ *
+ * Return value: %TRUE if a group with the name @group_name
+ * exists. Otherwise, @error is set and %FALSE is returned.
+ *
+ * Since: 2.30
+ * Rename to: g_key_file_has_key
+ **/
+gboolean
+g_key_file_has_key_full (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ gboolean *has_key,
+ GError **error)
+{
GKeyFileKeyValuePair *pair;
GKeyFileGroup *group;
pair = g_key_file_lookup_key_value_pair (key_file, group, key);
- return pair != NULL;
+ if (has_key)
+ *has_key = pair != NULL;
+ return TRUE;
}
static void
gsize len;
gchar *start;
GError *error = NULL;
+ gboolean has_key;
const gchar *data =
"[group1]\n"
g_key_file_has_key (keyfile, "no-such-group", "key", &error);
check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
+ g_assert (g_key_file_has_key_full (keyfile, "group1", "key1", &has_key, &error));
+ check_no_error (&error);
+ g_assert (has_key);
+
+ g_assert (g_key_file_has_key_full (keyfile, "group2", "key3", &has_key, &error));
+ check_no_error (&error);
+ g_assert (has_key);
+
+ g_assert (g_key_file_has_key_full (keyfile, "group2", "no-such-key", &has_key, &error));
+ g_assert (!has_key);
+ check_no_error (&error);
+
+ g_assert (!g_key_file_has_key_full (keyfile, "no-such-group", "key", &has_key, &error));
+ check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
+
g_key_file_free (keyfile);
}