/[mailutils]/mailutils/mailbox/list.c
ViewVC logotype

Diff of /mailutils/mailbox/list.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.20 by alainm, Fri Oct 10 02:04:28 2003 UTC revision 1.21 by gray, Fri Oct 24 09:39:08 2003 UTC
# Line 280  list_get (list_t list, size_t indx, void Line 280  list_get (list_t list, size_t indx, void
280  int  int
281  list_do (list_t list, list_action_t * action, void *cbdata)  list_do (list_t list, list_action_t * action, void *cbdata)
282  {  {
283    struct list_data *current;    iterator_t itr;
284    int status = 0;    int status = 0;
285        
286    if (list == NULL || action == NULL)    if (list == NULL || action == NULL)
287      return EINVAL;      return EINVAL;
288      status = iterator_create(&itr, list);
289      if (status)
290        return status;
291    monitor_rdlock (list->monitor);    monitor_rdlock (list->monitor);
292    for (current = list->head.next; current != &(list->head);    for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
        current = current->next)  
293      {      {
294          void *item;
295          iterator_current (itr, &item);
296        if ((status = action (current->item, cbdata)))        if ((status = action (current->item, cbdata)))
297          break;          break;
298      }      }
299    monitor_unlock (list->monitor);    monitor_unlock (list->monitor);
300      iterator_destroy (&itr);
301    return status;    return status;
302  }  }
303    
# Line 309  list_to_array (list_t list, void **array Line 314  list_to_array (list_t list, void **array
314  {  {
315    size_t total = 0;    size_t total = 0;
316    
317    if (list != NULL)    if (!list)
318        return EINVAL;
319      
320      total = (count < list->count) ? count : list->count;
321    
322      if (array)
323      {      {
324        size_t i;        size_t i;
325        struct list_data *current;        struct list_data *current;
326        total = (count < list->count) ? count : list->count;        
327        for (i = 0, current = list->head.next; i < total && current != &(list->head); current = current->next)        for (i = 0, current = list->head.next;
328          {             i < total && current != &(list->head); current = current->next)
329            if (array)          array[i] = current->item;
             array[i] = current->item;  
         }  
330      }      }
331    if (pcount)    if (pcount)
332      *pcount = total;      *pcount = total;

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26