core: add ROUND_UP() macro

pull/24503/head
Ben Noordhuis 2012-03-27 15:42:51 +02:00
parent 9d1fde7519
commit a58659cd4a
1 changed files with 7 additions and 3 deletions

View File

@ -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++