hipack-list.c 826 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * hipack-list.c
  3. * Copyright (C) 2015 Adrian Perez <aperez@igalia.com>
  4. *
  5. * Distributed under terms of the MIT license.
  6. */
  7. #include "hipack.h"
  8. #include <stdlib.h>
  9. static hipack_list_t s_empty_list = { .size = 0 };
  10. hipack_list_t*
  11. hipack_list_new (uint32_t size)
  12. {
  13. hipack_list_t *list;
  14. if (size) {
  15. list = hipack_alloc_array_extra (NULL, size,
  16. sizeof (hipack_value_t),
  17. sizeof (hipack_list_t));
  18. list->size = size;
  19. } else {
  20. list = &s_empty_list;
  21. }
  22. return list;
  23. }
  24. void
  25. hipack_list_free (hipack_list_t *list)
  26. {
  27. if (list && list != &s_empty_list) {
  28. for (uint32_t i = 0; i < list->size; i++)
  29. hipack_value_free (&list->data[i]);
  30. hipack_alloc_free (list);
  31. }
  32. }