2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 static slist_node_t *__util_del_first_node(slist_t *l_ptr);
25 void _util_init_list(slist_t *l_ptr)
27 ret_if(l_ptr == NULL);
36 mtp_bool _util_add_node(slist_t *l_ptr, void *data)
38 retv_if(l_ptr == NULL, FALSE);
40 slist_node_t *node = NULL;
42 node = (slist_node_t *)g_malloc(sizeof(slist_node_t));
44 ERR("g_malloc() Fail"); // LCOV_EXCL_LINE
45 return FALSE; // LCOV_EXCL_LINE
51 if (l_ptr->start == NULL)
54 l_ptr->end->link = node;
62 slist_node_t* _util_delete_node(slist_t *l_ptr, void *data)
64 retv_if(data == NULL, NULL);
65 retv_if(l_ptr == NULL, NULL);
66 retv_if(l_ptr->start == NULL, NULL);
68 slist_node_t *nptr = l_ptr->start;
69 slist_node_t *temp = NULL;
71 if (nptr->value == data)
72 return __util_del_first_node(l_ptr);
75 if (nptr->link->value == data)
80 if (nptr->link == NULL) {
81 ERR("Node not found in the list");
86 nptr->link = nptr->link->link;
89 if (temp == l_ptr->end)
95 static slist_node_t *__util_del_first_node(slist_t *l_ptr)
97 slist_node_t *temp = NULL;
101 l_ptr->start = temp->link;
102 if (temp == l_ptr->end)
109 /* This API will send NULL if list does not have elements */
110 slist_iterator* _util_init_list_iterator(slist_t *l_ptr)
112 slist_iterator *temp = NULL;
114 retv_if(l_ptr == NULL, NULL);
115 retv_if(l_ptr->start == NULL, NULL);
117 temp = (slist_iterator *)g_malloc(sizeof(slist_iterator));
119 ERR("g_malloc() Fail"); // LCOV_EXCL_LINE
120 return NULL; // LCOV_EXCL_LINE
123 temp->node_ptr = l_ptr->start;
127 /* Befor calling this please make sure
128 next element exists using _util_check_list_next */
129 void* _util_get_list_next(slist_iterator *iter)
131 slist_node_t *temp = NULL;
133 retv_if(iter == NULL, NULL);
135 temp = iter->node_ptr;
136 iter->node_ptr = iter->node_ptr->link;
141 /* LCOV_EXCL_START */
142 slist_node_t* _util_get_first_node(slist_t *l_ptr)
144 retv_if(l_ptr == NULL, NULL);
150 void _util_deinit_list_iterator(slist_iterator *iter)
152 ret_if(iter == NULL);