Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Sunxi Tools
Commits
5a970809
Commit
5a970809
authored
May 04, 2012
by
Alejandro Mery
Browse files
sunxi-tools.h: add container_of() helper
parent
b65db76e
Changes
1
Show whitespace changes
Inline
Side-by-side
sunxi-tools.h
View file @
5a970809
...
...
@@ -17,6 +17,8 @@
#ifndef _SUNXI_TOOLS_H
#define _SUNXI_TOOLS_H
#include <stddef.h>
/* offsetof */
/** flat function argument as unused */
#ifdef UNUSED
#elif defined(__GNUC__)
...
...
@@ -25,6 +27,11 @@
# define UNUSED(x) UNUSED_ ## x
#endif
/** finds the parent of an struct member */
#ifndef container_of
#define container_of(P,T,M) (T *)((char *)(P) - offsetof(T, M))
#endif
/** shortcut to printf to stderr */
#define errf(...) fprintf(stderr, __VA_ARGS__)
...
...
@@ -51,7 +58,7 @@ static inline void list_append(struct list_entry *l0, struct list_entry *l1)
/** returns list element of a list */
static
inline
struct
list_entry
*
list_last
(
struct
list_entry
*
l
)
{
return
(
l
->
prev
==
l
)
?
(
void
*
)
0
:
l
->
prev
;
return
(
l
->
prev
==
l
)
?
NULL
:
l
->
prev
;
}
/** is list empty? */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment