/* tf.h - libtf helper defines * * Copyright (C) 2009 Timo Teräs * All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 or later as * published by the Free Software Foundation. * * See http://www.gnu.org/ for details. */ #ifndef TF_DEFINES_H #define TF_DEFINES_H #include #include #include #ifndef NULL #define NULL 0L #endif #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef array_size #define array_size(array) (sizeof(array) / sizeof((array)[0])) #endif #ifndef offsetof #define offsetof(type, member) __builtin_offsetof (type, member) #endif #ifndef container_of #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) #endif #ifndef likely #define likely(x) __builtin_expect(!!(x), 1) #endif #ifndef unlikely #define unlikely(x) __builtin_expect(!!(x), 0) #endif #define attribute_never_inline __attribute__((noinline)) #define attribute_weak_function __attribute__((weak)) #define TF_BUG_ON(cond) if (cond) { \ fprintf(stderr, "BUG: failure at %s:%d/%s(): %s!\n", \ __FILE__, __LINE__, __func__, #cond); \ abort(); \ } #define TF_ALIGN(size,align) ((((size_t)(size)) + (align)-1) & ~((align)-1)) #define TF_EMPTY_ARRAY 0 #endif