g_string_free (values, TRUE);
}
-static void
-g_key_file_set_key_comment (GKeyFile *key_file,
- const gchar *group_name,
- const gchar *key,
- const gchar *comment,
- GError **error)
+static gboolean
+g_key_file_set_key_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ const gchar *comment,
+ GError **error)
{
GKeyFileGroup *group;
GKeyFileKeyValuePair *pair;
_("Key file does not have group '%s'"),
group_name ? group_name : "(null)");
- return;
+ return FALSE;
}
/* First find the key the comments are supposed to be
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s' in group '%s'"),
key, group->name);
- return;
+ return FALSE;
}
/* Then find all the comments already associated with the
}
if (comment == NULL)
- return;
+ return TRUE;
/* Now we can add our new comment
*/
pair->value = g_key_file_parse_comment_as_value (key_file, comment);
key_node = g_list_insert (key_node, pair, 1);
+
+ return TRUE;
}
-static void
-g_key_file_set_group_comment (GKeyFile *key_file,
- const gchar *group_name,
- const gchar *comment,
- GError **error)
+static gboolean
+g_key_file_set_group_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *comment,
+ GError **error)
{
GKeyFileGroup *group;
- g_return_if_fail (g_key_file_is_group_name (group_name));
+ g_return_val_if_fail (g_key_file_is_group_name (group_name), FALSE);
group = g_key_file_lookup_group (key_file, group_name);
if (!group)
_("Key file does not have group '%s'"),
group_name ? group_name : "(null)");
- return;
+ return FALSE;
}
/* First remove any existing comment
}
if (comment == NULL)
- return;
+ return TRUE;
/* Now we can add our new comment
*/
group->comment = g_slice_new (GKeyFileKeyValuePair);
group->comment->key = NULL;
group->comment->value = g_key_file_parse_comment_as_value (key_file, comment);
+
+ return TRUE;
}
-static void
-g_key_file_set_top_comment (GKeyFile *key_file,
- const gchar *comment,
- GError **error)
+static gboolean
+g_key_file_set_top_comment (GKeyFile *key_file,
+ const gchar *comment,
+ GError **error)
{
GList *group_node;
GKeyFileGroup *group;
}
if (comment == NULL)
- return;
+ return TRUE;
pair = g_slice_new (GKeyFileKeyValuePair);
pair->key = NULL;
group->key_value_pairs =
g_list_prepend (group->key_value_pairs, pair);
+
+ return TRUE;
}
/**
* @error: return location for a #GError
*
* Places a comment above @key from @group_name.
- * @group_name. If @key is %NULL then @comment will
- * be written above @group_name. If both @key
- * and @group_name are NULL, then @comment will
- * be written above the first group in the file.
+ * If @key is %NULL then @comment will be written
+ * above @group_name. If both @key and @group_name
+ * are NULL, then @comment will be written above
+ * the first group in the file.
+ *
+ * Returns: %TRUE if the comment was written, %FALSE otherwise
*
* Since: 2.6
**/
-void
-g_key_file_set_comment (GKeyFile *key_file,
- const gchar *group_name,
- const gchar *key,
- const gchar *comment,
- GError **error)
+gboolean
+g_key_file_set_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ const gchar *comment,
+ GError **error)
{
- g_return_if_fail (key_file != NULL);
+ g_return_val_if_fail (key_file != NULL, FALSE);
- if (group_name != NULL && key != NULL)
- g_key_file_set_key_comment (key_file, group_name, key, comment, error);
- else if (group_name != NULL)
- g_key_file_set_group_comment (key_file, group_name, comment, error);
- else
- g_key_file_set_top_comment (key_file, comment, error);
+ if (group_name != NULL && key != NULL)
+ {
+ if (!g_key_file_set_key_comment (key_file, group_name, key, comment, error))
+ return FALSE;
+ }
+ else if (group_name != NULL)
+ {
+ if (!g_key_file_set_group_comment (key_file, group_name, comment, error))
+ return FALSE;
+ }
+ else
+ {
+ if (!g_key_file_set_top_comment (key_file, comment, error))
+ return FALSE;
+ }
if (comment != NULL)
key_file->approximate_size += strlen (comment);
+
+ return TRUE;
}
static gchar *
-g_key_file_get_key_comment (GKeyFile *key_file,
- const gchar *group_name,
- const gchar *key,
- GError **error)
+g_key_file_get_key_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ GError **error)
{
GKeyFileGroup *group;
GKeyFileKeyValuePair *pair;
}
static gchar *
-g_key_file_get_group_comment (GKeyFile *key_file,
- const gchar *group_name,
- GError **error)
+g_key_file_get_group_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ GError **error)
{
GList *group_node;
GKeyFileGroup *group;
}
static gchar *
-g_key_file_get_top_comment (GKeyFile *key_file,
- GError **error)
+g_key_file_get_top_comment (GKeyFile *key_file,
+ GError **error)
{
GList *group_node;
GKeyFileGroup *group;
* Since: 2.6
**/
gchar *
-g_key_file_get_comment (GKeyFile *key_file,
- const gchar *group_name,
- const gchar *key,
- GError **error)
+g_key_file_get_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ GError **error)
{
g_return_val_if_fail (key_file != NULL, NULL);
* and @group_name are NULL, then @comment will
* be written above the first group in the file.
*
+ * Returns: %TRUE if the comment was removed, %FALSE otherwise
+ *
* Since: 2.6
**/
-void
-g_key_file_remove_comment (GKeyFile *key_file,
- const gchar *group_name,
- const gchar *key,
- GError **error)
+gboolean
+g_key_file_remove_comment (GKeyFile *key_file,
+ const gchar *group_name,
+ const gchar *key,
+ GError **error)
{
- g_return_if_fail (key_file != NULL);
+ g_return_val_if_fail (key_file != NULL, FALSE);
if (group_name != NULL && key != NULL)
- g_key_file_set_key_comment (key_file, group_name, key, NULL, error);
+ return g_key_file_set_key_comment (key_file, group_name, key, NULL, error);
else if (group_name != NULL)
- g_key_file_set_group_comment (key_file, group_name, NULL, error);
+ return g_key_file_set_group_comment (key_file, group_name, NULL, error);
else
- g_key_file_set_top_comment (key_file, NULL, error);
+ return g_key_file_set_top_comment (key_file, NULL, error);
}
/**
* Removes the specified group, @group_name,
* from the key file.
*
+ * Returns: %TRUE if the group was removed, %FALSE otherwise
+ *
* Since: 2.6
**/
-void
+gboolean
g_key_file_remove_group (GKeyFile *key_file,
const gchar *group_name,
GError **error)
{
GList *group_node;
- g_return_if_fail (key_file != NULL);
- g_return_if_fail (group_name != NULL);
+ g_return_val_if_fail (key_file != NULL, FALSE);
+ g_return_val_if_fail (group_name != NULL, FALSE);
group_node = g_key_file_lookup_group_node (key_file, group_name);
G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
_("Key file does not have group '%s'"),
group_name);
- return;
+ return FALSE;
}
- g_key_file_remove_group_node (key_file, group_node);
+ g_key_file_remove_group_node (key_file, group_node);
+
+ return TRUE;
}
static void
*
* Removes @key in @group_name from the key file.
*
+ * Returns: %TRUE if the key was removed, %FALSE otherwise
+ *
* Since: 2.6
**/
-void
+gboolean
g_key_file_remove_key (GKeyFile *key_file,
const gchar *group_name,
const gchar *key,
GKeyFileGroup *group;
GKeyFileKeyValuePair *pair;
- g_return_if_fail (key_file != NULL);
- g_return_if_fail (group_name != NULL);
- g_return_if_fail (key != NULL);
+ g_return_val_if_fail (key_file != NULL, FALSE);
+ g_return_val_if_fail (group_name != NULL, FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
pair = NULL;
G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
_("Key file does not have group '%s'"),
group_name ? group_name : "(null)");
- return;
+ return FALSE;
}
pair = g_key_file_lookup_key_value_pair (key_file, group, key);
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
_("Key file does not have key '%s' in group '%s'"),
key, group->name);
- return;
+ return FALSE;
}
key_file->approximate_size -= strlen (pair->key) + strlen (pair->value) + 2;
group->key_value_pairs = g_list_remove (group->key_value_pairs, pair);
g_hash_table_remove (group->lookup_map, pair->key);
g_key_file_key_value_pair_free (pair);
+
+ return TRUE;
}
static GList *