Changeset feeac0d in mainline for uspace/lib/c/include/adt/list.h
- Timestamp:
- 2013-09-10T16:32:35Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4982d87
- Parents:
- e8d6ce2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/list.h
re8d6ce2 rfeeac0d 67 67 ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member)))) 68 68 69 #define list_foreach(list, iterator) \ 70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 69 #define list_foreach(list, member, itype, iterator) \ 70 for (itype *iterator = NULL; iterator == NULL; iterator =(itype *)1) \ 71 for (link_t *_link = (list).head.next; \ 72 iterator = list_get_instance(_link, itype, member), \ 73 _link != &(list).head; _link = _link->next) 72 74 73 75 /** Unlike list_foreach(), allows removing items while traversing a list. … … 238 240 static inline link_t *list_last(list_t *list) 239 241 { 240 return ((list->head.prev == &list->head) ? NULL : list->head.prev); 242 return (list->head.prev == &list->head) ? NULL : list->head.prev; 243 } 244 245 /** Get next item in list. 246 * 247 * @param link Current item link 248 * @param list List containing @a link 249 * 250 * @return Next item or NULL if @a link is the last item. 251 */ 252 static inline link_t *list_next(link_t *link, const list_t *list) 253 { 254 return (link->next == &list->head) ? NULL : link->next; 255 } 256 257 /** Get previous item in list. 258 * 259 * @param link Current item link 260 * @param list List containing @a link 261 * 262 * @return Previous item or NULL if @a link is the first item. 263 */ 264 static inline link_t *list_prev(link_t *link, const list_t *list) 265 { 266 return (link->prev == &list->head) ? NULL : link->prev; 241 267 } 242 268 … … 308 334 unsigned int cnt = 0; 309 335 310 list_foreach(*list, link) { 336 link_t *link = list_first(list); 337 while (link != NULL) { 311 338 if (cnt == n) 312 339 return link; 313 340 314 341 cnt++; 342 link = list_next(link, list); 315 343 } 316 344
Note:
See TracChangeset
for help on using the changeset viewer.