From f45c1e101209c2d33f0659b1c0810bb575c66713 Mon Sep 17 00:00:00 2001 From: Tad Marshall Date: Mon, 17 Oct 2011 18:49:25 -0400 Subject: [PATCH] Add MSVC support Test for _WIN32 to check for building for Windows. Test __MINGW32__ to check for using MinGW compiler (on Windows). If _WIN32 is defined and __MINGW32__ is not defined, assume Microsoft compiler, headers and libraries. There are other ways this could be done, testing _MSC_VER for example, but these tests work. Tested with Visual Studio 2005, MinGW 4.6.1 on Windows (mingw-get-inst-20110802.exe) and gcc 4.6.1 in Ubuntu 11.10 (Ubuntu/Linaro 4.6.1-9ubuntu3). --- linenoise.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/linenoise.c b/linenoise.c index 9740366..926c972 100644 --- a/linenoise.c +++ b/linenoise.c @@ -102,18 +102,28 @@ * This support based in part on work by Jon Griffiths. */ -#ifdef __MINGW32__ +#ifdef _WIN32 /* Windows platform, either MinGW or Visual Studio (MSVC) */ #include #include #define USE_WINCONSOLE +#ifdef __MINGW32__ +#define HAVE_UNISTD_H +#else +/* Microsoft headers don't like old POSIX names */ +#define strdup _strdup +#define snprintf _snprintf +#endif #else #include #include #include #define USE_TERMIOS +#define HAVE_UNISTD_H #endif +#ifdef HAVE_UNISTD_H #include +#endif #include #include #include @@ -121,7 +131,6 @@ #include #include #include -#include #include "linenoise.h" #include "utf8.h" -- 2.44.0