llist.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef HEADER_CURL_LLIST_H
  2. #define HEADER_CURL_LLIST_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "curl_setup.h"
  27. #include <stddef.h>
  28. typedef void (*Curl_llist_dtor)(void *user, void *elem);
  29. /* none of these struct members should be referenced directly, use the
  30. dedicated functions */
  31. struct Curl_llist {
  32. struct Curl_llist_node *_head;
  33. struct Curl_llist_node *_tail;
  34. Curl_llist_dtor _dtor;
  35. size_t _size;
  36. #ifdef DEBUGBUILD
  37. int _init; /* detect API usage mistakes */
  38. #endif
  39. };
  40. struct Curl_llist_node {
  41. struct Curl_llist *_list; /* the list where this belongs */
  42. void *_ptr;
  43. struct Curl_llist_node *_prev;
  44. struct Curl_llist_node *_next;
  45. #ifdef DEBUGBUILD
  46. int _init; /* detect API usage mistakes */
  47. #endif
  48. };
  49. void Curl_llist_init(struct Curl_llist *, Curl_llist_dtor);
  50. void Curl_llist_insert_next(struct Curl_llist *, struct Curl_llist_node *,
  51. const void *, struct Curl_llist_node *node);
  52. void Curl_llist_append(struct Curl_llist *,
  53. const void *, struct Curl_llist_node *node);
  54. void Curl_node_uremove(struct Curl_llist_node *, void *);
  55. void Curl_node_remove(struct Curl_llist_node *);
  56. void Curl_llist_destroy(struct Curl_llist *, void *);
  57. /* Curl_llist_head() returns the first 'struct Curl_llist_node *', which
  58. might be NULL */
  59. struct Curl_llist_node *Curl_llist_head(struct Curl_llist *list);
  60. /* Curl_llist_tail() returns the last 'struct Curl_llist_node *', which
  61. might be NULL */
  62. struct Curl_llist_node *Curl_llist_tail(struct Curl_llist *list);
  63. /* Curl_llist_count() returns a size_t the number of nodes in the list */
  64. size_t Curl_llist_count(struct Curl_llist *list);
  65. /* Curl_node_elem() returns the custom data from a Curl_llist_node */
  66. void *Curl_node_elem(struct Curl_llist_node *n);
  67. /* Curl_node_next() returns the next element in a list from a given
  68. Curl_llist_node */
  69. struct Curl_llist_node *Curl_node_next(struct Curl_llist_node *n);
  70. /* Curl_node_prev() returns the previous element in a list from a given
  71. Curl_llist_node */
  72. struct Curl_llist_node *Curl_node_prev(struct Curl_llist_node *n);
  73. /* Curl_node_llist() return the list the node is in or NULL. */
  74. struct Curl_llist *Curl_node_llist(struct Curl_llist_node *n);
  75. #endif /* HEADER_CURL_LLIST_H */