From: hujianyang Date: Thu, 16 Oct 2014 12:02:09 +0000 (+0800) Subject: mtd-utils: Add macros to include/common.h X-Git-Tag: v1.5.2~20 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a167204782941dae63a3318a9c26bde040c7b049;p=mtd-utils.git mtd-utils: Add macros to include/common.h This patch adds four macros: ALIGN, __ALIGN_MASK, min_t and max_t to include/common.h. Signed-off-by: hujianyang --- diff --git a/include/common.h b/include/common.h index 6895e5c..9b8804a 100644 --- a/include/common.h +++ b/include/common.h @@ -47,6 +47,21 @@ extern "C" { #define min(a, b) MIN(a, b) /* glue for linux kernel source */ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) + +#define min_t(t,x,y) ({ \ + typeof((x)) _x = (x); \ + typeof((y)) _y = (y); \ + (_x < _y) ? _x : _y; \ +}) + +#define max_t(t,x,y) ({ \ + typeof((x)) _x = (x); \ + typeof((y)) _y = (y); \ + (_x > _y) ? _x : _y; \ +}) + #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif