/* Returns: (array zero-terminated=1) (transfer full): a newly-allocated NULL-terminated array of strings. Use g_strfreev() to free it. Since: 2.6  */
gchar** g_key_file_get_groups(GKeyFile *key_file, gsize *length)
/* Returns: (array zero-terminated=1) (transfer full): a newly-allocated NULL-terminated array of strings. Use g_strfreev() to free it. Since: 2.6  */
gchar** g_key_file_get_groups(GKeyFile *key_file, gsize *length)
{
  GList *group_node;
  gchar **groups;
  gsize i, num_groups;
  g_return_val_if_fail (key_file != NULL, NULL);
  num_groups = g_list_length (key_file->groups);
  g_return_val_if_fail (num_groups > 0, NULL);
  group_node = g_list_last (key_file->groups);
  g_return_val_if_fail (((GKeyFileGroup *) group_node->data)->name == NULL, NULL);
  groups = g_new (gchar *, num_groups);
  i = 0;
  for (group_node = group_node->prev;
       group_node != NULL;
       group_node = group_node->prev)
    {
      GKeyFileGroup *group;
      group = (GKeyFileGroup *) group_node->data;
      g_warn_if_fail (group->name != NULL);
      groups[i++] = g_strdup (group->name);
    }
  groups[i] = NULL;
  if (length)
    *length = i;
  return groups;
}