Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from gnu99 to c99. #52

Merged
merged 3 commits into from
Sep 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ VERSION := 0.4

LIBS := -levent
CFLAGS += -g -O2
override CFLAGS += -std=gnu99 -Wall
override CFLAGS += -std=c99 -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -Wall

all: $(OUT)

Expand Down
38 changes: 19 additions & 19 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ static inline void list_splice_init(struct list_head_t *list,
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
for (pos = list_entry((head)->next, __typeof(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
pos = list_entry(pos->member.next, __typeof(*pos), member))

/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
Expand All @@ -311,9 +311,9 @@ static inline void list_splice_init(struct list_head_t *list,
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member); \
for (pos = list_entry((head)->prev, __typeof(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, typeof(*pos), member))
pos = list_entry(pos->member.prev, __typeof(*pos), member))

/**
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue
Expand All @@ -324,7 +324,7 @@ static inline void list_splice_init(struct list_head_t *list,
* Prepares a pos entry for use as a start point in list_for_each_entry_continue.
*/
#define list_prepare_entry(pos, head, member) \
((pos) ? : list_entry(head, typeof(*pos), member))
((pos) ? : list_entry(head, __typeof(*pos), member))

/**
* list_for_each_entry_continue - continue iteration over list of given type
Expand All @@ -336,9 +336,9 @@ static inline void list_splice_init(struct list_head_t *list,
* the current position.
*/
#define list_for_each_entry_continue(pos, head, member) \
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
for (pos = list_entry(pos->member.next, __typeof(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
pos = list_entry(pos->member.next, __typeof(*pos), member))

/**
* list_for_each_entry_from - iterate over list of given type from the current point
Expand All @@ -350,7 +350,7 @@ static inline void list_splice_init(struct list_head_t *list,
*/
#define list_for_each_entry_from(pos, head, member) \
for (; &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
pos = list_entry(pos->member.next, __typeof(*pos), member))

/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Expand All @@ -360,10 +360,10 @@ static inline void list_splice_init(struct list_head_t *list,
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
for (pos = list_entry((head)->next, __typeof(*pos), member), \
n = list_entry(pos->member.next, __typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
pos = n, n = list_entry(n->member.next, __typeof(*n), member))

/**
* list_for_each_entry_safe_continue
Expand All @@ -376,10 +376,10 @@ static inline void list_splice_init(struct list_head_t *list,
* safe against removal of list entry.
*/
#define list_for_each_entry_safe_continue(pos, n, head, member) \
for (pos = list_entry(pos->member.next, typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
for (pos = list_entry(pos->member.next, __typeof(*pos), member), \
n = list_entry(pos->member.next, __typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
pos = n, n = list_entry(n->member.next, __typeof(*n), member))

/**
* list_for_each_entry_safe_from
Expand All @@ -392,9 +392,9 @@ static inline void list_splice_init(struct list_head_t *list,
* removal of list entry.
*/
#define list_for_each_entry_safe_from(pos, n, head, member) \
for (n = list_entry(pos->member.next, typeof(*pos), member); \
for (n = list_entry(pos->member.next, __typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
pos = n, n = list_entry(n->member.next, __typeof(*n), member))

/**
* list_for_each_entry_safe_reverse
Expand All @@ -407,9 +407,9 @@ static inline void list_splice_init(struct list_head_t *list,
* of list entry.
*/
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member), \
n = list_entry(pos->member.prev, typeof(*pos), member); \
for (pos = list_entry((head)->prev, __typeof(*pos), member), \
n = list_entry(pos->member.prev, __typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
pos = n, n = list_entry(n->member.prev, __typeof(*n), member))

#endif
14 changes: 11 additions & 3 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ struct sockaddr_in;
#endif


#ifdef __GNUC__
#define member_type(type, member) __typeof(((type *)0)->member)
#else
#define member_type(type, member) const void
#endif

/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#define container_of(ptr, type, member) \
((type *)( \
(char *)(member_type(type, member) *){ ptr } - offsetof(type, member) \
))


#define clamp_value(value, min_val, max_val) do { \
if (value < min_val) \
Expand Down