quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

llist.h (3404B)


      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 
     27 #include "curl_setup.h"
     28 #include <stddef.h>
     29 
     30 typedef void (*Curl_llist_dtor)(void *user, void *elem);
     31 
     32 /* none of these struct members should be referenced directly, use the
     33    dedicated functions */
     34 
     35 struct Curl_llist {
     36   struct Curl_llist_node *_head;
     37   struct Curl_llist_node *_tail;
     38   Curl_llist_dtor _dtor;
     39   size_t _size;
     40 #ifdef DEBUGBUILD
     41   int _init;      /* detect API usage mistakes */
     42 #endif
     43 };
     44 
     45 struct Curl_llist_node {
     46   struct Curl_llist *_list; /* the list where this belongs */
     47   void *_ptr;
     48   struct Curl_llist_node *_prev;
     49   struct Curl_llist_node *_next;
     50 #ifdef DEBUGBUILD
     51   int _init;      /* detect API usage mistakes */
     52 #endif
     53 };
     54 
     55 void Curl_llist_init(struct Curl_llist *, Curl_llist_dtor);
     56 void Curl_llist_insert_next(struct Curl_llist *, struct Curl_llist_node *,
     57                             const void *, struct Curl_llist_node *node);
     58 void Curl_llist_append(struct Curl_llist *,
     59                        const void *, struct Curl_llist_node *node);
     60 void Curl_node_remove(struct Curl_llist_node *);
     61 void Curl_llist_destroy(struct Curl_llist *, void *);
     62 
     63 /* Curl_llist_head() returns the first 'struct Curl_llist_node *', which
     64    might be NULL */
     65 struct Curl_llist_node *Curl_llist_head(struct Curl_llist *list);
     66 
     67 /* Curl_llist_tail() returns the last 'struct Curl_llist_node *', which
     68    might be NULL */
     69 struct Curl_llist_node *Curl_llist_tail(struct Curl_llist *list);
     70 
     71 /* Curl_llist_count() returns a size_t the number of nodes in the list */
     72 size_t Curl_llist_count(struct Curl_llist *list);
     73 
     74 /* Curl_node_elem() returns the custom data from a Curl_llist_node */
     75 void *Curl_node_elem(struct Curl_llist_node *n);
     76 
     77 /* Remove the node from the list and return the custom data
     78  * from a Curl_llist_node. Will NOT invoke a registered `dtor`. */
     79 void *Curl_node_take_elem(struct Curl_llist_node *);
     80 
     81 /* Curl_node_next() returns the next element in a list from a given
     82    Curl_llist_node */
     83 struct Curl_llist_node *Curl_node_next(struct Curl_llist_node *n);
     84 
     85 /* Curl_node_prev() returns the previous element in a list from a given
     86    Curl_llist_node */
     87 struct Curl_llist_node *Curl_node_prev(struct Curl_llist_node *n);
     88 
     89 /* Curl_node_llist() return the list the node is in or NULL. */
     90 struct Curl_llist *Curl_node_llist(struct Curl_llist_node *n);
     91 
     92 #endif /* HEADER_CURL_LLIST_H */