diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2021-12-01 21:53:15 +0800 |
---|---|---|
committer | Gao Xiang <xiang@kernel.org> | 2021-12-02 09:46:13 +0800 |
commit | 519dbd2368240c4c6d159459ab5614e1d9540c3c (patch) | |
tree | 45b5804f92d5ce225347db5435f8690ccbf01924 /include/erofs/defs.h | |
parent | c816397a43b050fff84337b4484e67f72cb5501a (diff) | |
download | erofs-utils-519dbd2368240c4c6d159459ab5614e1d9540c3c.tar.gz |
erofs-utils: make liberofs more C++ friendly
1. Add extern "C" wrappers to headers, so that they can be included
from C++
2. Add const keywords to certain pointer type params
Link: https://lore.kernel.org/r/20211201135315.3732-1-xiang@kernel.org
Signed-off-by: Kelvin Zhang <zhangkelvin@google.com>
Signed-off-by: Gao Xiang <xiang@kernel.org>
Diffstat (limited to 'include/erofs/defs.h')
-rw-r--r-- | include/erofs/defs.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/include/erofs/defs.h b/include/erofs/defs.h index 6398cbb..4db237f 100644 --- a/include/erofs/defs.h +++ b/include/erofs/defs.h @@ -8,6 +8,11 @@ #ifndef __EROFS_DEFS_H #define __EROFS_DEFS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stddef.h> #include <stdint.h> #include <assert.h> @@ -82,7 +87,9 @@ typedef int64_t s64; #endif #endif -#ifndef __OPTIMIZE__ +#ifdef __cplusplus +#define BUILD_BUG_ON(condition) static_assert(!(condition)) +#elif !defined(__OPTIMIZE__) #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) #else #define BUILD_BUG_ON(condition) assert(!(condition)) @@ -110,6 +117,8 @@ typedef int64_t s64; } \ ) +/* Can easily conflict with C++'s std::min */ +#ifndef __cplusplus #define min(x, y) ({ \ typeof(x) _min1 = (x); \ typeof(y) _min2 = (y); \ @@ -121,6 +130,7 @@ typedef int64_t s64; typeof(y) _max2 = (y); \ (void) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) +#endif /* * ..and if you can't take the strict types, you can specify one yourself. @@ -308,4 +318,9 @@ unsigned long __roundup_pow_of_two(unsigned long n) #define stat64 stat #define lstat64 lstat #endif + +#ifdef __cplusplus +} +#endif + #endif |