Search code examples
clinuxglibdoubly-linked-list

how to edit an existing data in glib lists


I use glib's lists (linked-lists) for storing a list of strings in my program. I'm already able to append, prepend or insert new items to the list but I can't edit an existing item in the list. I cannot find the appropriate function for editing items in glib's documentation. Is there any functions implemented in glib for doing this?


Solution

  • I think you're supposed to use the structure directly, as the internal structure is exposed:

    struct GList {
      gpointer data;
      GList *next;
      GList *prev;
    };
    

    So, for example:

    GList *bar = g_list_last(foo);
    bar->data = NULL; //for instance