Changeset feeac0d in mainline for uspace/lib/c
- 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
- Location:
- uspace/lib/c
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/hash_table.c
re8d6ce2 rfeeac0d 227 227 228 228 /* Check for duplicates. */ 229 list_foreach(h->bucket[idx], cur) {229 list_foreach(h->bucket[idx], link, ht_link_t, cur_link) { 230 230 /* 231 231 * We could filter out items using their hashes first, but 232 232 * calling equal() might very well be just as fast. 233 233 */ 234 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);235 234 if (h->op->equal(cur_link, item)) 236 235 return false; … … 258 257 size_t idx = h->op->key_hash(key) % h->bucket_cnt; 259 258 260 list_foreach(h->bucket[idx], cur) { 261 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link); 259 list_foreach(h->bucket[idx], link, ht_link_t, cur_link) { 262 260 /* 263 261 * Is this is the item we are looking for? We could have first -
uspace/lib/c/generic/adt/list.c
re8d6ce2 rfeeac0d 102 102 unsigned int count = 0; 103 103 104 list_foreach(*list, link) { 104 link_t *link = list_first(list); 105 while (link != NULL) { 105 106 count++; 107 link = list_next(link, list); 106 108 } 107 109 -
uspace/lib/c/generic/cfg.c
re8d6ce2 rfeeac0d 83 83 return true; 84 84 85 list_foreach(data->sections, link) { 86 const cfg_section_t *section = cfg_section_instance(link); 87 85 cfg_file_foreach(data, section) { 88 86 if (!list_empty(§ion->entries)) 89 87 return false; … … 413 411 const cfg_section_t *cfg_find_section(const cfg_file_t *data, const char *title) 414 412 { 415 list_foreach(data->sections, link) { 416 const cfg_section_t *section = cfg_section_instance(link); 417 413 cfg_file_foreach(data, section) { 418 414 if (str_cmp(section->title, title) == 0) 419 415 return section; … … 434 430 const char *cfg_find_value(const cfg_section_t *section, const char *key) 435 431 { 436 list_foreach(section->entries, link) { 437 const cfg_entry_t *entry = cfg_entry_instance(link); 438 432 cfg_section_foreach(section, entry) { 439 433 if (str_cmp(entry->key, key) == 0) 440 434 return entry->value; -
uspace/lib/c/generic/devman.c
re8d6ce2 rfeeac0d 230 230 } 231 231 232 match_id_t *match_id = NULL; 233 234 list_foreach(match_ids->ids, link) { 235 match_id = list_get_instance(link, match_id_t, link); 236 232 list_foreach(match_ids->ids, link, match_id_t, match_id) { 237 233 ipc_call_t answer2; 238 234 aid_t req2 = async_send_1(exch, DEVMAN_ADD_MATCH_ID, -
uspace/lib/c/generic/pio_trace.c
re8d6ce2 rfeeac0d 95 95 pio_regions_t *regions = get_regions(); 96 96 fibril_rwlock_read_lock(®ions->guard); 97 list_foreach(regions->list, it) { 98 assert(it); 99 region_t *reg = region_instance(it); 100 assert(reg); 97 list_foreach(regions->list, link, region_t, reg) { 101 98 if ((r >= reg->base) && (r < reg->base + reg->size)) { 102 99 if (reg->log) … … 131 128 fibril_rwlock_write_lock(®ions->guard); 132 129 list_foreach_safe(regions->list, it, next) { 133 assert(it);134 130 region_t *reg = region_instance(it); 135 assert(reg);136 131 if (r >= reg->base && (r < reg->base + reg->size)) { 137 138 132 list_remove(®->link); 133 region_destroy(reg); 139 134 } 140 135 } -
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 -
uspace/lib/c/include/cfg.h
re8d6ce2 rfeeac0d 80 80 81 81 #define cfg_file_foreach(file, cur) \ 82 list_foreach((file)->sections, (cur))82 list_foreach((file)->sections, link, const cfg_section_t, (cur)) 83 83 84 84 #define cfg_section_instance(cur) \ … … 86 86 87 87 #define cfg_section_foreach(section, cur) \ 88 list_foreach((section)->entries, (cur))88 list_foreach((section)->entries, link, const cfg_entry_t, (cur)) 89 89 90 90 #define cfg_entry_instance(cur) \
Note:
See TracChangeset
for help on using the changeset viewer.