Skip to content

Commit

Permalink
Enable building on Windows with Visual Studio.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jim Hague committed Oct 15, 2019
1 parent b8df261 commit 5db0d03
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 26 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/anchor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions src/compat/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,4 +71,4 @@ int gettimeofday(struct timeval* tv, struct timezone* tz)

return 0;
}
#endif /* GETDNS_ON_WINDOWS */
#endif /* HAVE_GETTIMEOFDAY */
4 changes: 2 additions & 2 deletions src/compat/inet_ntop.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <config.h>

#ifndef HAVE_INET_NTOP
#ifndef HAVE_DECL_INET_NTOP

#include <sys/param.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions src/compat/inet_pton.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <config.h>

#ifndef HAVE_DECL_INET_PTON

#include <string.h>
#include <stdio.h>
#include <errno.h>
Expand Down Expand Up @@ -228,3 +230,4 @@ inet_pton6(src, dst)
memcpy(dst, tmp, NS_IN6ADDRSZ);
return (1);
}
#endif /* HAVE_DECL_INET_PTON */
1 change: 0 additions & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 0 additions & 1 deletion src/dnssec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions src/getdns/getdns_extra.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions src/gldns/gbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/gldns/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "gldns/gbuffer.h"

#include <limits.h>
#include <strings.h>

gldns_lookup_table gldns_directive_types[] = {
{ GLDNS_DIR_TTL, "$TTL" },
Expand Down
1 change: 0 additions & 1 deletion src/gldns/parseutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "config.h"
#include "gldns/parseutil.h"
#include <sys/time.h>
#include <time.h>
#include <ctype.h>

Expand Down
2 changes: 2 additions & 0 deletions src/gldns/wire2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ssl_dane
Submodule ssl_dane updated 1 files
+1 −0 danessl.c
1 change: 0 additions & 1 deletion src/tls/anchor-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 20 additions & 11 deletions src/util/lookup3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/util/orig-headers/locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 5db0d03

Please sign in to comment.