VirtualBox

source: vbox/trunk/src/libs/curl-7.83.1/lib/llist.c@ 96762

Last change on this file since 96762 was 95312, checked in by vboxsync, 3 years ago

libs/{curl,libxml2}: OSE export fixes, bugref:8515

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2021, Daniel Stenberg, <[email protected]>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22
23#include "curl_setup.h"
24
25#include <curl/curl.h>
26
27#include "llist.h"
28#include "curl_memory.h"
29
30/* this must be the last include file */
31#include "memdebug.h"
32
33/*
34 * @unittest: 1300
35 */
36void
37Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor)
38{
39 l->size = 0;
40 l->dtor = dtor;
41 l->head = NULL;
42 l->tail = NULL;
43}
44
45/*
46 * Curl_llist_insert_next()
47 *
48 * Inserts a new list element after the given one 'e'. If the given existing
49 * entry is NULL and the list already has elements, the new one will be
50 * inserted first in the list.
51 *
52 * The 'ne' argument should be a pointer into the object to store.
53 *
54 * @unittest: 1300
55 */
56void
57Curl_llist_insert_next(struct Curl_llist *list, struct Curl_llist_element *e,
58 const void *p,
59 struct Curl_llist_element *ne)
60{
61 ne->ptr = (void *) p;
62 if(list->size == 0) {
63 list->head = ne;
64 list->head->prev = NULL;
65 list->head->next = NULL;
66 list->tail = ne;
67 }
68 else {
69 /* if 'e' is NULL here, we insert the new element first in the list */
70 ne->next = e?e->next:list->head;
71 ne->prev = e;
72 if(!e) {
73 list->head->prev = ne;
74 list->head = ne;
75 }
76 else if(e->next) {
77 e->next->prev = ne;
78 }
79 else {
80 list->tail = ne;
81 }
82 if(e)
83 e->next = ne;
84 }
85
86 ++list->size;
87}
88
89/*
90 * @unittest: 1300
91 */
92void
93Curl_llist_remove(struct Curl_llist *list, struct Curl_llist_element *e,
94 void *user)
95{
96 void *ptr;
97 if(!e || list->size == 0)
98 return;
99
100 if(e == list->head) {
101 list->head = e->next;
102
103 if(!list->head)
104 list->tail = NULL;
105 else
106 e->next->prev = NULL;
107 }
108 else {
109 if(e->prev)
110 e->prev->next = e->next;
111
112 if(!e->next)
113 list->tail = e->prev;
114 else
115 e->next->prev = e->prev;
116 }
117
118 ptr = e->ptr;
119
120 e->ptr = NULL;
121 e->prev = NULL;
122 e->next = NULL;
123
124 --list->size;
125
126 /* call the dtor() last for when it actually frees the 'e' memory itself */
127 if(list->dtor)
128 list->dtor(user, ptr);
129}
130
131void
132Curl_llist_destroy(struct Curl_llist *list, void *user)
133{
134 if(list) {
135 while(list->size > 0)
136 Curl_llist_remove(list, list->tail, user);
137 }
138}
139
140size_t
141Curl_llist_count(struct Curl_llist *list)
142{
143 return list->size;
144}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette