Enable building on Windows with Visual Studio.

The change mostly consists of removing or replacing non-standard (usually POSIX) header includes.

Guards for replacements for inet_ntop(), inet_pton() and gettimeofday() are updated; the first two are macros on Windows, so the guards are changed to HAVE_DECL. gettimeofday() is present on MinGW builds but not Visual Studio, so that has a function check.
This commit is contained in:
Jim Hague 2019-10-15 10:09:17 +01:00
parent b8df26194e
commit 5db0d03b13
16 changed files with 53 additions and 26 deletions

View File

@ -1495,6 +1495,8 @@ dnl ---------------------------------------------------------------------------
AC_CHECK_HEADERS([stdarg.h stdint.h netinet/in.h arpa/inet.h netdb.h sys/socket.h time.h sys/time.h sys/select.h endian.h limits.h sys/limits.h],,, [AC_INCLUDES_DEFAULT])
AC_REPLACE_FUNCS(gettimeofday)
dnl Check the printf-format attribute (if any)
dnl result in HAVE_ATTR_FORMAT.
dnl
@ -1729,6 +1731,10 @@ int inet_pton(int af, const char* src, void* dst);
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
#endif
#ifndef HAVE_GETTIMEOFDAY
int gettimeofday(struct timeval* tv, void* tz);
#endif
#ifdef USE_WINSOCK
# ifndef _CUSTOM_VSNPRINTF
# define _CUSTOM_VSNPRINTF

View File

@ -33,7 +33,7 @@
#include "debug.h"
#include "anchor.h"
#include <fcntl.h>
#include <strings.h>
#include <string.h>
#include <time.h>
#include "types-internal.h"
#include "context.h"

View File

@ -21,8 +21,9 @@
*/
#include "config.h"
#ifdef GETDNS_ON_WINDOWS
int gettimeofday(struct timeval* tv, struct timezone* tz)
#ifndef HAVE_GETTIMEOFDAY
int gettimeofday(struct timeval* tv, void* tz)
{
FILETIME ft;
uint64_t now = 0;
@ -70,4 +71,4 @@ int gettimeofday(struct timeval* tv, struct timezone* tz)
return 0;
}
#endif /* GETDNS_ON_WINDOWS */
#endif /* HAVE_GETTIMEOFDAY */

View File

@ -19,7 +19,7 @@
#include <config.h>
#ifndef HAVE_INET_NTOP
#ifndef HAVE_DECL_INET_NTOP
#include <sys/param.h>
#include <sys/types.h>
@ -215,4 +215,4 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
return (dst);
}
#endif /* !HAVE_INET_NTOP */
#endif /* !HAVE_DECL_INET_NTOP */

View File

@ -18,6 +18,8 @@
#include <config.h>
#ifndef HAVE_DECL_INET_PTON
#include <string.h>
#include <stdio.h>
#include <errno.h>
@ -228,3 +230,4 @@ inet_pton6(src, dst)
memcpy(dst, tmp, NS_IN6ADDRSZ);
return (1);
}
#endif /* HAVE_DECL_INET_PTON */

View File

@ -55,7 +55,6 @@ typedef unsigned short in_port_t;
#include <sys/stat.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -192,7 +192,6 @@
#include "debug.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include "getdns/getdns.h"
#include "context.h"

View File

@ -36,10 +36,14 @@
#define _GETDNS_EXTRA_H_
#include <getdns/getdns.h>
#include <sys/time.h>
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#if defined(_WIN32)
/* For struct timeval, see getdns_context_get_num_pending_requests */
#include <winsock2.h>
#else
#include <sys/time.h>
#endif
#ifdef __cplusplus
extern "C" {

View File

@ -13,6 +13,12 @@
#ifndef GLDNS_SBUFFER_H
#define GLDNS_SBUFFER_H
#include <stdint.h>
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -13,7 +13,6 @@
#include "gldns/gbuffer.h"
#include <limits.h>
#include <strings.h>
gldns_lookup_table gldns_directive_types[] = {
{ GLDNS_DIR_TTL, "$TTL" },

View File

@ -14,7 +14,6 @@
#include "config.h"
#include "gldns/parseutil.h"
#include <sys/time.h>
#include <time.h>
#include <ctype.h>

View File

@ -25,7 +25,9 @@
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <stdarg.h>
#include <ctype.h>
#ifdef HAVE_NETDB_H

@ -1 +1 @@
Subproject commit dd093e585a237e0321d303ec35e84c393ef739f4
Subproject commit ae85ab134df4762d8f6396fee93c04ed1ebdf152

View File

@ -37,7 +37,6 @@
#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <strings.h>
#include <time.h>
#include "types-internal.h"
#include "context.h"

View File

@ -49,8 +49,16 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
#include "util/storage/lookup3.h"
#include <stdio.h> /* defines printf for tests */
#include <time.h> /* defines time_t for timings in the test */
/*#include <stdint.h> defines uint32_t etc (from config.h) */
#include <sys/param.h> /* attempt to define endianness */
#if defined(HAVE_TARGET_ENDIANNESS)
# if defined(TARGET_IS_BIG_ENDIAN)
# define HASH_LITTLE_ENDIAN 0
# define HASH_BIG_ENDIAN 1
# else
# define HASH_LITTLE_ENDIAN 1
# define HASH_BIG_ENDIAN 0
# endif
#else
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> /* attempt to define endianness (solaris) */
#endif
@ -65,15 +73,6 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
#include <sys/endian.h> /* attempt to define endianness */
#endif
/* random initial value */
static uint32_t raninit = (uint32_t)0xdeadbeef;
void
hash_set_raninit(uint32_t v)
{
raninit = v;
}
/*
* My best guess at if you are big-endian or little-endian. This may
* need adjustment.
@ -103,6 +102,16 @@ hash_set_raninit(uint32_t v)
# define HASH_LITTLE_ENDIAN 0
# define HASH_BIG_ENDIAN 0
#endif
#endif /* defined(TARGET_IS_BIG_ENDIAN) */
/* random initial value */
static uint32_t raninit = (uint32_t)0xdeadbeef;
void
hash_set_raninit(uint32_t v)
{
raninit = v;
}
#define hashsize(n) ((uint32_t)1<<(n))
#define hashmask(n) (hashsize(n)-1)

View File

@ -219,6 +219,7 @@ void* ub_thread_key_get(ub_thread_key_type key);
#else /* we do not HAVE_SOLARIS_THREADS and no PTHREADS */
/******************* WINDOWS THREADS ************************/
#ifdef HAVE_WINDOWS_THREADS
#include <winsock2.h>
#include <windows.h>
/* Use a mutex */