]> git.lizzy.rs Git - linenoise.git/commitdiff
Add MSVC support
authorTad Marshall <tad@tadmarshall.com>
Mon, 17 Oct 2011 22:49:25 +0000 (18:49 -0400)
committerSteve Bennett <steveb@workware.net.au>
Mon, 30 Jan 2012 02:40:37 +0000 (12:40 +1000)
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

index 9740366afd4ab3bac7329f38feef002101fe0b89..926c9721df63e1e976d7c344b343e4b28ead7384 100644 (file)
  * This support based in part on work by Jon Griffiths.
  */
 
-#ifdef __MINGW32__
+#ifdef _WIN32 /* Windows platform, either MinGW or Visual Studio (MSVC) */
 #include <windows.h>
 #include <fcntl.h>
 #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 <termios.h>
 #include <sys/ioctl.h>
 #include <sys/poll.h>
 #define USE_TERMIOS
+#define HAVE_UNISTD_H
 #endif
 
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
-#include <unistd.h>
 
 #include "linenoise.h"
 #include "utf8.h"