From 82a68f4457e370375568fb647f48a5ec54e953da Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 26 Dec 2019 20:55:53 +0000 Subject: [PATCH] Windows: Update code to build on Windows Add in specific _WIN32 definitions for the missing functionality from recent PR updates. R_OK (used by access()) strndup() strcasecmp() --- examples/client.c | 9 +++++++++ examples/coap-server.c | 12 ++++++++++++ src/coap_openssl.c | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/examples/client.c b/examples/client.c index a1f606f2..ce170951 100644 --- a/examples/client.c +++ b/examples/client.c @@ -21,6 +21,15 @@ #if !defined(S_ISDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +static char* strndup(const char* s1, size_t n) +{ + char* copy = (char*)malloc(n + 1); + if (copy) { + memcpy(copy, s1, n); + copy[n] = 0; + } + return copy; +}; #else #include #include diff --git a/examples/coap-server.c b/examples/coap-server.c index 94274f26..b3d59d65 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -23,6 +23,18 @@ #if !defined(S_ISDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +#ifndef R_OK +#define R_OK 4 +#endif +static char* strndup(const char* s1, size_t n) +{ + char* copy = (char*)malloc(n + 1); + if (copy) { + memcpy(copy, s1, n); + copy[n] = 0; + } + return copy; +}; #else #include #include diff --git a/src/coap_openssl.c b/src/coap_openssl.c index 2662c4eb..517ad207 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -60,6 +60,10 @@ #define UNUSED #endif /* __GNUC__ */ +#ifdef _WIN32 +#define strcasecmp _stricmp +#endif + /* RFC6091/RFC7250 */ #ifndef TLSEXT_TYPE_client_certificate_type #define TLSEXT_TYPE_client_certificate_type 19