g_key_file_has_key_full: New function to fix g_key_file_has_key()'s GError semantics
[platform/upstream/glib.git] / glib / gkeyfile.c
index 31c2a15..3afd781 100644 (file)
@@ -3130,14 +3130,22 @@ g_key_file_has_group (GKeyFile    *key_file,
 }
 
 /**
- * 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.
@@ -3150,6 +3158,44 @@ g_key_file_has_key (GKeyFile     *key_file,
                    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;
 
@@ -3171,7 +3217,9 @@ g_key_file_has_key (GKeyFile     *key_file,
 
   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