mirror of https://github.com/nodejs/node.git
core: add ROUND_UP() macro
parent
9d1fde7519
commit
a58659cd4a
|
@ -29,17 +29,21 @@ namespace node {
|
||||||
#ifndef offset_of
|
#ifndef offset_of
|
||||||
// g++ in strict mode complains loudly about the system offsetof() macro
|
// g++ in strict mode complains loudly about the system offsetof() macro
|
||||||
// because it uses NULL as the base address.
|
// because it uses NULL as the base address.
|
||||||
#define offset_of(type, member) \
|
# define offset_of(type, member) \
|
||||||
((intptr_t) ((char *) &(((type *) 8)->member) - 8))
|
((intptr_t) ((char *) &(((type *) 8)->member) - 8))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef container_of
|
#ifndef container_of
|
||||||
#define container_of(ptr, type, member) \
|
# define container_of(ptr, type, member) \
|
||||||
((type *) ((char *) (ptr) - offset_of(type, member)))
|
((type *) ((char *) (ptr) - offset_of(type, member)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ARRAY_SIZE
|
#ifndef ARRAY_SIZE
|
||||||
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
|
# define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ROUND_UP
|
||||||
|
# define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// this would have been a template function were it not for the fact that g++
|
// this would have been a template function were it not for the fact that g++
|
||||||
|
|
Loading…
Reference in New Issue