Move duplicate min() and max() macro definitions from individual source files (alloc.c, fallocate.c, rehash.c) to the common ext2fs.h header. Add include guards to prevent redefinition warnings when files define their own versions of these macros before including ext2fs.h. Signed-off-by: Artem Blagodarenko Reviewed-by: Andreas Dilger --- lib/ext2fs/alloc.c | 2 -- lib/ext2fs/ext2fs.h | 9 +++++++++ lib/ext2fs/fallocate.c | 1 - misc/e4defrag.c | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c index 3fd921679..ff29b888e 100644 --- a/lib/ext2fs/alloc.c +++ b/lib/ext2fs/alloc.c @@ -26,8 +26,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#define min(a, b) ((a) < (b) ? (a) : (b)) - #undef DEBUG #ifdef DEBUG diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index c4fcb10be..374b8289e 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -134,6 +134,15 @@ typedef struct ext2fs_struct_generic_bitmap_base *ext2fs_block_bitmap; #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s) +/* + * Utility macros + */ +#ifndef min +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif /* * Badblocks list definitions diff --git a/lib/ext2fs/fallocate.c b/lib/ext2fs/fallocate.c index 1ef989cd3..82c18ab75 100644 --- a/lib/ext2fs/fallocate.c +++ b/lib/ext2fs/fallocate.c @@ -17,7 +17,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#define min(a, b) ((a) < (b) ? (a) : (b)) #undef DEBUG diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 68e937fdb..e07f28cf6 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -59,7 +59,6 @@ fprintf(stderr, "\t%s\n", (msg)) #define STATISTIC_ERR_MSG_WITH_ERRNO(msg) \ fprintf(stderr, "\t%s:%s\n", (msg), strerror(errno)) -#define min(x, y) (((x) > (y)) ? (y) : (x)) #define CALC_SCORE(ratio) \ ((ratio) > 10 ? (80 + 20 * (ratio) / 100) : (8 * (ratio))) /* Wrap up the free function */ -- 2.43.7