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");
51 if (l_ptr->start == NULL)
54 l_ptr->end->link = node;
61 slist_node_t* _util_delete_node(slist_t *l_ptr, void *data)
63 retv_if(data == NULL, NULL);
64 retv_if(l_ptr == NULL, NULL);
65 retv_if(l_ptr->start == NULL, NULL);
67 slist_node_t *nptr = l_ptr->start;
68 slist_node_t *temp = NULL;
70 if (nptr->value == data)
71 return __util_del_first_node(l_ptr);
74 if (nptr->link->value == data)
79 if (nptr->link == NULL) {
80 ERR("Node not found in the list");
85 nptr->link = nptr->link->link;
88 if (temp == l_ptr->end)
94 static slist_node_t *__util_del_first_node(slist_t *l_ptr)
96 slist_node_t *temp = NULL;
100 l_ptr->start = temp->link;
101 if (temp == l_ptr->end)
107 /* This API will send NULL if list does not have elements */
108 slist_iterator* _util_init_list_iterator(slist_t *l_ptr)
110 slist_iterator *temp = NULL;
112 retv_if(l_ptr == NULL, NULL);
113 retv_if(l_ptr->start == NULL, NULL);
115 temp = (slist_iterator *)g_malloc(sizeof(slist_iterator));
117 ERR("g_malloc() Fail");
121 temp->node_ptr = l_ptr->start;
125 /* Befor calling this please make sure
126 next element exists using _util_check_list_next */
127 void* _util_get_list_next(slist_iterator *iter)
129 slist_node_t *temp = NULL;
131 retv_if(iter == NULL, NULL);
133 temp = iter->node_ptr;
134 iter->node_ptr = iter->node_ptr->link;
139 slist_node_t* _util_get_first_node(slist_t *l_ptr)
141 retv_if(l_ptr == NULL, NULL);
146 void _util_deinit_list_iterator(slist_iterator *iter)
148 ret_if(iter == NULL);