Re: G_LIST_REMOVE not working... at least not for me :-)



On Sat, Nov 16, 2002 at 03:50:05PM -0800, Mike Dailey wrote:

mainConnMgmtComboList = g_list_remove
(mainConnMgmtComboList,
g_strdup(FMC->appCURMGMTHOST.c_str()));

C doesn't work this way; it doesn't know what the void* in the 
GSList points to. You have to remove the string using exactly the 
same pointer used to add the string.

GList*
remove_string_by_value (GList *list, const char *str)
{
  GList *iter;
  iter = list;
  while (iter != NULL)
    {                   
      const char *s = iter->data;
      if (strcmp (s, str) == 0)
        return g_list_remove (list, iter->data);
      iter = iter->next;
    }
  return list;
}

You can make it more efficient by unlinking the list node "iter" when
the string matches, instead of using g_list_remove which scans from
the front of the list, but it's somewhat more tricky.

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]