diff --git a/src/libratbag-util.h b/src/libratbag-util.h index 50516984..d2c12234 100644 --- a/src/libratbag-util.h +++ b/src/libratbag-util.h @@ -46,16 +46,6 @@ void list_insert(struct list *list, struct list *elm); void list_remove(struct list *elm); int list_empty(const struct list *list); -#ifdef __GNUC__ -#define container_of(ptr, sample, member) \ - (__typeof__(sample))((char *)(ptr) - \ - ((char *)&(sample)->member - (char *)(sample))) -#else -#define container_of(ptr, sample, member) \ - (void *)((char *)(ptr) - \ - ((char *)&(sample)->member - (char *)(sample))) -#endif - #define list_for_each(pos, head, member) \ for (pos = 0, pos = container_of((head)->next, pos, member); \ &pos->member != (head); \ @@ -69,16 +59,6 @@ int list_empty(const struct list *list); pos = tmp, \ tmp = container_of(pos->member.next, tmp, member)) -#define LONG_BITS (sizeof(long) * 8) -#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) -#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) -#define ARRAY_FOR_EACH(_arr, _elem) \ - for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++) -#define AS_MASK(v) (1 << (v)) - -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#define max(a, b) (((a) > (b)) ? (a) : (b)) - static inline void cleanup_free(void *p) { free(*(void**)p); diff --git a/src/shared-macro.h b/src/shared-macro.h index 98ba0f2c..a10d418c 100644 --- a/src/shared-macro.h +++ b/src/shared-macro.h @@ -76,6 +76,27 @@ #define _weak_ __attribute__((weak)) #define _weakref_(_x) __attribute__((weakref(#_x))) +/* container_of macro */ +#ifdef __GNUC__ +#define container_of(ptr, sample, member) \ + (__typeof__(sample))((char *)(ptr) - \ + ((char *)&(sample)->member - (char *)(sample))) +#else +#define container_of(ptr, sample, member) \ + (void *)((char *)(ptr) - \ + ((char *)&(sample)->member - (char *)(sample))) +#endif + +#define LONG_BITS (sizeof(long) * 8) +#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) +#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) +#define ARRAY_FOR_EACH(_arr, _elem) \ + for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++) +#define AS_MASK(v) (1 << (v)) + +#define min(a, b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) + /* * DECIMAL_TOKEN_MAX() - calculate maximum length of the decimal representation * of an integer