~ubuntu-branches/ubuntu/karmic/vzctl/karmic

« back to all changes in this revision

Viewing changes to include/list.h

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2000-2006 SWsoft. All rights reserved.
 
2
 *  Copyright (C) 2000-2007 SWsoft. All rights reserved.
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
20
20
#define _LIST_H_
21
21
 
22
22
 
23
 
struct list_elem;
24
 
typedef struct {
25
 
        struct list_elem *prev, *next;
26
 
} list_head_t;
27
 
 
28
 
typedef struct list_elem {
29
 
        struct list_elem *prev, *next;
30
 
} list_elem_t;
 
23
struct list_head {
 
24
        struct list_head *prev, *next;
 
25
};
 
26
typedef struct list_head list_head_t;
 
27
typedef struct list_head list_elem_t;
31
28
 
32
29
struct str_struct {
33
30
        list_elem_t list;
38
35
 
39
36
static inline void list_head_init(list_head_t *head)
40
37
{
41
 
        head->next = (list_elem_t *)head;
42
 
        head->prev = (list_elem_t *)head;
 
38
        head->next = head;
 
39
        head->prev = head;
43
40
}
44
41
 
45
42
static inline void list_elem_init(list_elem_t *entry)
51
48
static inline void list_add(list_elem_t *new, list_head_t *list)
52
49
{
53
50
        new->next = list->next;
54
 
        new->prev = (list_elem_t *)list;
 
51
        new->prev = list;
55
52
        list->next->prev = new;
56
53
        list->next = new;
57
54
}
58
55
 
59
56
static inline void list_add_tail(list_elem_t *new, list_head_t *list)
60
57
{
61
 
        new->next = (list_elem_t *)list;
 
58
        new->next = list;
62
59
        new->prev = list->prev;
63
60
        list->prev->next = new;
64
61
        list->prev = new;
81
78
 
82
79
static inline int list_is_init(list_head_t *h)
83
80
{
84
 
        return h->next == NULL;
 
81
        return h->next == NULL;
85
82
}
86
83
 
87
84
static inline int list_empty(list_head_t *h)
88
85
{
89
86
        if (list_is_init(h))
90
87
                return 1;
91
 
        return h->next == (list_elem_t *)h;
 
88
        return h->next == h;
92
89
}
93
90
 
94
91
static inline int list_elem_inserted(list_elem_t *el)
98
95
 
99
96
static inline void list_moveall(list_head_t *src, list_head_t *dst)
100
97
{
101
 
        list_add((list_elem_t *)dst, src);
102
 
        list_del((list_elem_t *)src);
 
98
        list_add(dst, src);
 
99
        list_del(src);
103
100
        list_head_init(src);
104
101
}
105
102
 
111
108
 
112
109
#define list_for_each(entry, head, field)                               \
113
110
        for (entry = list_entry((head)->next, typeof(*entry), field);\
114
 
             &entry->field != (list_elem_t*)(head);                     \
 
111
             &entry->field != (head);                                   \
115
112
             entry = list_entry(entry->field.next, typeof(*entry), field))
116
113
 
117
114
#define list_for_each_prev(entry, head, field)                          \
118
115
        for (entry = list_entry((head)->prev, typeof(*entry), field);\
119
 
             &entry->field != (list_elem_t*)(head);                     \
 
116
             &entry->field != (head);                                   \
120
117
             entry = list_entry(entry->field.prev, typeof(*entry), field))
121
118
 
122
119
#define list_for_each_safe(entry, tmp, head, field)                     \
123
120
        for (entry = list_entry((head)->next, typeof(*entry), field),\
124
121
                tmp = list_entry(entry->field.next, typeof(*entry), field); \
125
 
             &entry->field != (list_elem_t*)(head);                     \
 
122
             &entry->field != (head);                                   \
126
123
             entry = tmp,                                               \
127
 
                tmp = list_entry(tmp->field.next, typeof(*tmp), field))
 
124
             tmp = list_entry(tmp->field.next, typeof(*tmp), field))
128
125
 
129
126
 
130
127
char *list2str_c(char *name, char c, list_head_t *head);
137
134
int copy_str_param(list_head_t *dst, list_head_t *src);
138
135
char *find_str(list_head_t *head, const char *val);
139
136
int merge_str_list(int delall, list_head_t *old, list_head_t *add,
140
 
        list_head_t *del, list_head_t *merged);
 
137
        list_head_t *del, list_head_t *merged);
141
138
int list_size(list_head_t *head);
142
139
#endif /* _LIST_H_ */