aboutsummaryrefslogtreecommitdiff
path: root/include/compat.h
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-01 00:13:11 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-01 18:31:04 +0200
commita2495bd1ac9e5e54074d65616de0efa822a6309e (patch)
treee8a186b06bb4a94faafd7826b1ddc7c65112e824 /include/compat.h
parentb3f2636f44eea1a8b6fbf892d2daa611cff9d4af (diff)
Add preliminary VisualStudio support
- Mostly workarounds/clutches in compat.h - Change getline return type to int - Replace C99 style flexible array with alloca - Add all the MSVC solution/project crap Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/compat.h')
-rw-r--r--include/compat.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/include/compat.h b/include/compat.h
index b2bb054..5d7a052 100644
--- a/include/compat.h
+++ b/include/compat.h
@@ -27,6 +27,10 @@
# define SZ_ADD_OV __builtin_add_overflow
# define SZ_MUL_OV __builtin_mul_overflow
# endif
+#elif defined(_MSC_VER)
+# include <intsafe.h>
+# define SZ_ADD_OV SizeTAdd
+# define SZ_MUL_OV SizeTMult
#else
# error I do not know how to trap integer overflows with this compiler
#endif
@@ -40,7 +44,13 @@
# define PRI_U32 "%" PRIu32
#endif
-#if SIZEOF_SIZE_T <= SIZEOF_INT
+#ifdef _MSC_VER
+# ifdef _WIN64
+# define PRI_SZ PRI_U64
+# else
+# define PRI_SZ PRI_U32
+# endif
+#elif SIZEOF_SIZE_T <= SIZEOF_INT
# define PRI_SZ "%u"
#elif SIZEOF_SIZE_T == SIZEOF_LONG
# define PRI_SZ "%lu"
@@ -73,8 +83,17 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+
+#include <malloc.h>
+
+#ifdef _MSC_VER
+# define alloca _alloca
+#endif
+
+#define strdup _strdup
#else
#include <endian.h>
+#include <alloca.h>
#endif
#if defined(_WIN32) || defined(__WINDOWS__)
@@ -167,7 +186,7 @@ int chdir(const char *path);
#ifndef HAVE_GETLINE
#include <stdio.h>
-ssize_t getline(char **line, size_t *n, FILE *fp);
+int getline(char **line, size_t *n, FILE *fp);
#endif
#ifndef HAVE_STRNDUP