diff --git a/src/a2io.h b/src/a2io.h index 70a031c3..6e1196a6 100644 --- a/src/a2io.h +++ b/src/a2io.h @@ -146,6 +146,9 @@ # define a2open(path, flags, mode) _wsopen(path, flags, _SH_DENYNO, mode) # define a2fopen(path, mode) _wfsopen(path, mode, _SH_DENYNO) // # define a2ftruncate(fd, length): We don't use ftruncate in Mingw build +# ifndef off_t +# define off_t _off_t +# endif # define a2_off_t off_t #elif defined(__ANDROID__) || defined(ANDROID) # define a2lseek(fd, offset, origin) lseek64(fd, offset, origin) @@ -201,4 +204,31 @@ extern int ftruncate64(int fd, off64_t length); # define A2_BAD_FD -1 #endif // !__MINGW32__ +#if defined(_MSC_VER) +// Present with their _ prefixes on MSVC +# define O_RDONLY _O_RDONLY +# define O_WRONLY _O_WRONLY +# define O_RDWR _O_RDWR +# define O_APPEND _O_APPEND +# define O_CREAT _O_CREAT +# define O_EXCL _O_EXCL +# define O_TRUNC _O_TRUNC + +# define STDIN_FILENO _fileno(stdin) +#endif + +#if defined(_MSC_VER) +# define a2_isatty _isatty +# define a2_fileno _fileno +# define a2_read _read +# define a2_close _close +# define a2_dup _dup +#else +# define a2_isatty isatty +# define a2_fileno fileno +# define a2_read read +# define a2_close close +# define a2_dub dup +#endif // !_MSC_VER + #endif // D_A2IO_H diff --git a/src/a2netcompat.h b/src/a2netcompat.h index 8f0683d2..52e9ba87 100644 --- a/src/a2netcompat.h +++ b/src/a2netcompat.h @@ -84,7 +84,9 @@ #ifndef HAVE_GETADDRINFO # include "getaddrinfo.h" -# define HAVE_GAI_STRERROR +# ifndef HAVE_GAI_STRERROR +# define HAVE_GAI_STRERROR +# endif #endif // HAVE_GETADDRINFO #ifndef HAVE_GAI_STRERROR diff --git a/src/gai_strerror.h b/src/gai_strerror.h index effa6411..f88054af 100644 --- a/src/gai_strerror.h +++ b/src/gai_strerror.h @@ -56,7 +56,7 @@ extern "C" { /* * Functions. */ -#ifdef __STDC__ +#if defined(__STDC__) || defined(_MSC_VER) const char* gai_strerror(int); #else const char* gai_strerror(); diff --git a/src/getaddrinfo.c b/src/getaddrinfo.c index 59c29e04..0946c040 100644 --- a/src/getaddrinfo.c +++ b/src/getaddrinfo.c @@ -124,7 +124,7 @@ #ifndef HAVE_MEMCPY # define memcpy(d, s, n) bcopy((s), (d), (n)) -# ifdef __STDC__ +# if defined(__STDC__) || defined(_MSC_VER) void* memchr(const void*, int, size_t); int memcmp(const void*, const void*, size_t); void* memmove(void*, const void*, size_t); @@ -137,6 +137,10 @@ char* memset(); # endif /* not __STDC__ */ #endif /* not HAVE_MEMCPY */ +#if defined(_MSC_VER) +# define H_ERRNO_DECLARED 1 +#endif + #ifndef H_ERRNO_DECLARED extern int h_errno; #endif @@ -156,6 +160,11 @@ extern int h_errno; # define N_(string) (string) #endif +#if defined(_MSC_VER) +# include +# define in_port_t uint16_t +#endif + /* * Error messages for gai_strerror(). */ @@ -211,7 +220,7 @@ static pthread_mutex_t gai_mutex = PTHREAD_MUTEX_INITIALIZER; /* * Declaration of static functions. */ -#ifdef __STDC__ +#if defined(__STDC__) || defined(_MSC_VER) static int is_integer(const char*); static int is_address(const char*); static int itoa_length(int); @@ -494,7 +503,9 @@ struct addrinfo** res; *res = head_res; end: +#if !defined(_MSC_VER) // h_errno >> WSAGetLastError() ; not editable h_errno = saved_h_errno; +#endif #ifdef ENABLE_PTHREAD pthread_mutex_unlock(&gai_mutex); #endif @@ -588,7 +599,9 @@ int flags; } end: +#if !defined(_MSC_VER) // h_errno >> WSAGetLastError() ; not editable h_errno = saved_h_errno; +#endif #ifdef ENABLE_PTHREAD pthread_mutex_unlock(&gai_mutex); #endif diff --git a/src/getaddrinfo.h b/src/getaddrinfo.h index 7faaedc4..64eeccbf 100644 --- a/src/getaddrinfo.h +++ b/src/getaddrinfo.h @@ -41,7 +41,7 @@ extern "C" { # include "config.h" #endif // HAVE_CONFIG_H -#if defined(__MINGW32__) || defined(__MSVC__) +#if defined(__MINGW32__) || defined(_MSC_VER) # ifndef _WIN32_WINNT # define _WIN32_WINNT 0x501 # endif // _WIN32_WINNT @@ -240,7 +240,7 @@ extern "C" { #endif /* Nexenta OS(GNU/Solaris OS) defines `struct addrinfo' in netdb.h */ -#if !defined(__MINGW32__) && !defined(__sun) && !defined(_MSC_VER) +#if !defined(__MINGW32__) && !defined(__sun) // && !defined(_MSC_VER) /* * struct addrinfo. @@ -261,7 +261,7 @@ struct addrinfo { /* * Functions. */ -#ifdef __STDC__ +#if defined(__STDC__) || defined(_MSC_VER) const char* gai_strerror(int); void freeaddrinfo(struct addrinfo*); int getaddrinfo(const char*, const char*, const struct addrinfo*, diff --git a/src/gettimeofday.c b/src/gettimeofday.c index 8c7df499..76a53e12 100644 --- a/src/gettimeofday.c +++ b/src/gettimeofday.c @@ -23,7 +23,15 @@ * Danny Smith */ -#include +#include "config.h" + +#ifdef HAVE_SYS_TIME_H +# include +#endif + +#ifdef HAVE_WINSOCK2_H +# include +#endif /* HAVE_WINSOCK2_H */ #if defined(__MINGW32__) || defined(_MSC_VER) diff --git a/src/strptime.c b/src/strptime.c index a27e6aa5..072010d0 100644 --- a/src/strptime.c +++ b/src/strptime.c @@ -54,11 +54,21 @@ #endif // HAVE_ALLOCA_H #ifdef HAVE_MALLOC_H +# if defined(_MSC_VER) +// pull in alloca _alloca def +# define _CRT_INTERNAL_NONSTDC_NAMES 1 +# endif # include #endif // HAVE_MALLOC_H #include "strptime.h" +#if defined(_MSC_VER) +# define tzname _tzname +# define strncasecmp _strnicmp +# define strcasecmp _stricmp +#endif + static const char* abb_weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL}; diff --git a/src/util.h b/src/util.h index cdb6a950..0e567047 100644 --- a/src/util.h +++ b/src/util.h @@ -117,6 +117,11 @@ typedef SSIZE_T ssize_t; #endif +#if defined(_MSC_VER) +# define strdup _strdup +# define wdscup _wcsdup +#endif + namespace util { extern const char DEFAULT_STRIP_CHARSET[];