diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-23 16:24:08 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-23 16:46:49 +0100 |
commit | 650b607f339cd0ffa32e205e4501ec3fcfa88fbf (patch) | |
tree | c3ba2d5ac9709fa12e8d750a8bd82e727085c464 /include | |
parent | b4226fbb569bd39fa0198c0e823400836dd6cc2d (diff) |
Fix various data type problems
- Make sure the mockup constant for AT_FDCWD is actualy an int
- Don't use %lld printf format specified, mscrt doesn't have that
- On 64 bit windows, use %I64u format specified for size_t
- Seperate the overflow macro stuff from the form specifier stuff
- Move the whole thing to compat.h and clean it up a little so
it becomes readable.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r-- | include/compat.h | 34 | ||||
-rw-r--r-- | include/util/util.h | 28 |
2 files changed, 33 insertions, 29 deletions
diff --git a/include/compat.h b/include/compat.h index af2ac5a..26ad69b 100644 --- a/include/compat.h +++ b/include/compat.h @@ -7,6 +7,38 @@ #ifndef COMPAT_H #define COMPAT_H +#if defined(__GNUC__) || defined(__clang__) +# if defined(__GNUC__) && __GNUC__ < 5 +# if SIZEOF_SIZE_T <= SIZEOF_INT +# define SZ_ADD_OV __builtin_uadd_overflow +# define SZ_MUL_OV __builtin_umul_overflow +# elif SIZEOF_SIZE_T == SIZEOF_LONG +# define SZ_ADD_OV __builtin_uaddl_overflow +# define SZ_MUL_OV __builtin_umull_overflow +# elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG +# define SZ_ADD_OV __builtin_uaddll_overflow +# define SZ_MUL_OV __builtin_umulll_overflow +# else +# error Cannot determine maximum value of size_t +# endif +# else +# define SZ_ADD_OV __builtin_add_overflow +# define SZ_MUL_OV __builtin_mul_overflow +# endif +#else +# error I do not know how to trap integer overflows with this compiler +#endif + +#if SIZEOF_SIZE_T <= SIZEOF_INT +# define PRI_SZ "%u" +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define PRI_SZ "%lu" +#elif defined(_WIN32) && SIZEOF_SIZE_T == 8 +# define PRI_SZ "%I64u" +#else +# error Cannot figure out propper printf specifier for size_t +#endif + #if defined(__APPLE__) #include <libkern/OSByteOrder.h> @@ -99,7 +131,7 @@ struct stat { (((y)&0xffffff00ULL) << 12) | \ (((y)&0x000000ffULL)) ) -#define AT_FDCWD (0xDEADBEEF) +#define AT_FDCWD ((int)0xDEADBEEF) #define AT_SYMLINK_NOFOLLOW (0x01) int fchownat(int dirfd, const char *path, int uid, int gid, int flags); diff --git a/include/util/util.h b/include/util/util.h index 095f02a..a133067 100644 --- a/include/util/util.h +++ b/include/util/util.h @@ -18,34 +18,6 @@ #define container_of(ptr, type, member) \ ((type *)((char *)ptr - offsetof(type, member))) -#if defined(__GNUC__) || defined(__clang__) -#define UI_ADD_OV __builtin_uadd_overflow -#define UL_ADD_OV __builtin_uaddl_overflow -#define ULL_ADD_OV __builtin_uaddll_overflow - -#define UI_MUL_OV __builtin_umul_overflow -#define UL_MUL_OV __builtin_umull_overflow -#define ULL_MUL_OV __builtin_umulll_overflow -#else -#error Sorry, I do not know how to trap integer overflows with this compiler -#endif - -#if SIZEOF_SIZE_T <= SIZEOF_INT -#define SZ_ADD_OV UI_ADD_OV -#define SZ_MUL_OV UI_MUL_OV -#define PRI_SZ "%u" -#elif SIZEOF_SIZE_T == SIZEOF_LONG -#define SZ_ADD_OV UL_ADD_OV -#define SZ_MUL_OV UL_MUL_OV -#define PRI_SZ "%lu" -#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG -#define SZ_ADD_OV ULL_ADD_OV -#define SZ_MUL_OV ULL_MUL_OV -#define PRI_SZ "%llu" -#else -#error Cannot determine maximum value of size_t -#endif - /* Helper for allocating data structures with flexible array members. |