diff options
author | hujianyang <hujianyang@huawei.com> | 2014-10-16 20:02:09 +0800 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2014-10-20 13:41:56 +0300 |
commit | a167204782941dae63a3318a9c26bde040c7b049 (patch) | |
tree | b69b8c795d6b89f69bb9163a600d57be82364819 /include | |
parent | 15685fe39f1665d53d8b316c8f837f20f8700d4b (diff) |
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 <hujianyang@huawei.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/common.h | 15 |
1 files changed, 15 insertions, 0 deletions
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 |