Changeset 2246de6 in mainline


Ignore:
Timestamp:
2009-05-21T06:57:08Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cb41a5e
Parents:
55982d6
Message:

add list_count()
cstyle

Location:
uspace/lib/libc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/libadt/list.c

    r55982d6 r2246de6  
    4949int list_member(const link_t *link, const link_t *head)
    5050{
    51         int found = false;
     51        int found = 0;
    5252        link_t *hlp = head->next;
    5353       
    5454        while (hlp != head) {
    5555                if (hlp == link) {
    56                         found = true;
     56                        found = 1;
    5757                        break;
    5858                }
     
    7878        if (list_empty(head2))
    7979                return;
    80 
     80       
    8181        head2->next->prev = head1->prev;
    82         head2->prev->next = head1;     
     82        head2->prev->next = head1;
    8383        head1->prev->next = head2->next;
    8484        head1->prev = head2->prev;
     
    8686}
    8787
     88
     89/** Count list items
     90 *
     91 * Return the number of items in the list.
     92 *
     93 * @param link List to count.
     94 *
     95 * @return Number of items in the list.
     96 *
     97 */
     98unsigned int list_count(const link_t *link)
     99{
     100        unsigned int count = 0;
     101        link_t *hlp = link->next;
     102       
     103        while (hlp != link) {
     104                count++;
     105                hlp = hlp->next;
     106        }
     107       
     108        return count;
     109}
     110
    88111/** @}
    89112 */
  • uspace/lib/libc/include/libadt/list.h

    r55982d6 r2246de6  
    3838#include <unistd.h>
    3939
    40 #ifndef true
    41 # define true 1
    42 #endif
    43 #ifndef false
    44 # define false 0
    45 #endif
    46 
    47 typedef struct link link_t;
    48 
    4940/** Doubly linked list head and link type. */
    50 struct link {
    51         link_t *prev;   /**< Pointer to the previous item in the list. */
    52         link_t *next;   /**< Pointer to the next item in the list. */
    53 };
     41typedef struct link {
     42        struct link *prev;  /**< Pointer to the previous item in the list. */
     43        struct link *next;  /**< Pointer to the next item in the list. */
     44} link_t;
    5445
    5546/** Declare and initialize statically allocated list.
     
    5748 * @param name Name of the new statically allocated list.
    5849 */
    59 #define LIST_INITIALIZE(name)           link_t name = { .prev = &name, .next = &name }
     50#define LIST_INITIALIZE(name)  link_t name = { \
     51        .prev = &name, \
     52        .next = &name \
     53}
    6054
    6155/** Initialize doubly-linked circular list link
     
    146140static inline int list_empty(link_t *head)
    147141{
    148         return head->next == head ? true : false;
     142        return ((head->next == head) ? 1 : 0);
    149143}
    150144
     
    162156static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    163157{
    164         link_t *hlp;
    165 
    166158        part1->prev->next = part2;
    167         part2->prev->next = part1;     
    168         hlp = part1->prev;
     159        part2->prev->next = part1;
     160       
     161        link_t *hlp = part1->prev;
     162       
    169163        part1->prev = part2->prev;
    170164        part2->prev = hlp;
     
    196190}
    197191
    198 #define list_get_instance(link,type,member) (type *)(((char *)(link))-((char *)&(((type *)NULL)->member)))
     192#define list_get_instance(link, type, member)  ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
    199193
    200194extern int list_member(const link_t *link, const link_t *head);
    201195extern void list_concat(link_t *head1, link_t *head2);
     196extern unsigned int list_count(const link_t *link);
    202197
    203198#endif
Note: See TracChangeset for help on using the changeset viewer.