?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. /* l_list.c - basic list structure.
  2.  
  3.    This is free and unencumbered software released into the public domain.
  4.    For more information, please refer to <http://unlicense.org>. */
  5.  
  6. #include "defs.h"
  7.  
  8. #include <stddef.h>
  9. #include <stdlib.h>
  10. #include "l_list.h"
  11.  
  12. void
  13.     list_entry_clear
  14.     (
  15.         struct list_entry_t *self
  16.     )
  17. {
  18.     self->next = NULL;
  19. }
  20.  
  21. void
  22.     list_entry_free
  23.     (
  24.         struct list_entry_t *self
  25.     )
  26. {
  27.     list_entry_clear (self);
  28. }
  29.  
  30. void
  31.     list_clear
  32.     (
  33.         struct list_t *self
  34.     )
  35. {
  36.     self->first = NULL;
  37.     self->last = NULL;
  38.     self->count = 0;
  39. }
  40.  
  41. void
  42.     list_add_entry
  43.     (
  44.         struct list_t *self,
  45.         struct list_entry_t *p
  46.     )
  47. {
  48.     if (self->first)
  49.     {
  50.         self->last->next = p;
  51.         self->last = p;
  52.     }
  53.     else
  54.     {
  55.         self->first = p;
  56.         self->last = p;
  57.     }
  58.  
  59.     self->count++;
  60. }
  61.  
  62. void
  63.     list_free
  64.     (
  65.         struct list_t *self
  66.     )
  67. {
  68.     struct list_entry_t *p, *n;
  69.  
  70.     p = self->first;
  71.     while (p)
  72.     {
  73.         n = p->next;
  74.         list_entry_free (p);
  75.         free (p);
  76.         p = n;
  77.     }
  78.     list_clear (self);
  79. }
  80.