aboutsummaryrefslogtreecommitdiff
path: root/include/compat.h
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-23 16:24:08 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-23 16:46:49 +0100
commit650b607f339cd0ffa32e205e4501ec3fcfa88fbf (patch)
treec3ba2d5ac9709fa12e8d750a8bd82e727085c464 /include/compat.h
parentb4226fbb569bd39fa0198c0e823400836dd6cc2d (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/compat.h')
-rw-r--r--include/compat.h34
1 files changed, 33 insertions, 1 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);