From 2b0bb5a78d34933a4c0ab57713371bc3aec252c1 Mon Sep 17 00:00:00 2001 From: Sam Ellicott Date: Tue, 19 May 2020 23:19:58 -0400 Subject: [PATCH] Redefine strdup to make Windows happy --- colorchord2/chash.c | 9 ++++++++- colorchord2/hidapi.c | 7 +++++++ colorchord2/main.c | 7 ++++++- colorchord2/outdrivers.c | 7 +++++++ colorchord2/parameters.c | 7 +++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/colorchord2/chash.c b/colorchord2/chash.c index f4cc84f..a5e7c41 100644 --- a/colorchord2/chash.c +++ b/colorchord2/chash.c @@ -10,6 +10,13 @@ #include #include +#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) \ + || defined(_WIN32) || defined(_WIN64) +#ifndef strdup +#define strdup _strdup +#endif +#endif + #define I_AM_LITTLE (((union { unsigned x; unsigned char c; }){1}).c) static unsigned long GetStrHash( const char * c ) @@ -126,7 +133,7 @@ void ** HashTableInsert( struct chash * hash, const char * key, int dontDupKey ) } else { - thisEntry->key = strdup( key ); + thisEntry->key = _strdup( key ); } thisEntry->hash = thisHash; diff --git a/colorchord2/hidapi.c b/colorchord2/hidapi.c index 225c8a8..d1f9c2f 100644 --- a/colorchord2/hidapi.c +++ b/colorchord2/hidapi.c @@ -58,6 +58,13 @@ typedef LONG NTSTATUS; /*#define HIDAPI_USE_DDK*/ +#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) \ + || defined(_WIN32) || defined(_WIN64) +#ifndef strdup +#define strdup _strdup +#endif +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/colorchord2/main.c b/colorchord2/main.c index 53421f4..bb12d50 100644 --- a/colorchord2/main.c +++ b/colorchord2/main.c @@ -1,9 +1,14 @@ //Copyright 2015 <>< Charles Lohr under the ColorChord License. -#if defined(WIN32) || defined(USE_WINDOWS) +#if defined(WINDOWS) || defined(USE_WINDOWS)\ + || defined(WIN32) || defined(WIN64) \ + || defined(_WIN32) || defined(_WIN64) #include #include +#ifndef strdup +#define strdup _strdup #endif +#endif #include #include "color.h" diff --git a/colorchord2/outdrivers.c b/colorchord2/outdrivers.c index 6d3591b..5f604f5 100644 --- a/colorchord2/outdrivers.c +++ b/colorchord2/outdrivers.c @@ -7,6 +7,13 @@ #include #include +#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) \ + || defined(_WIN32) || defined(_WIN64) +#ifndef strdup +#define strdup _strdup +#endif +#endif + int force_white = 0; unsigned char OutLEDs[MAX_LEDS*3]; int UsedLEDs; diff --git a/colorchord2/parameters.c b/colorchord2/parameters.c index 3800694..d462b8f 100644 --- a/colorchord2/parameters.c +++ b/colorchord2/parameters.c @@ -6,6 +6,13 @@ #include #include +#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) \ + || defined(_WIN32) || defined(_WIN64) +#ifndef strdup +#define strdup _strdup +#endif +#endif + static struct chash * parameters; //XXX TODO: Make this thread safe.