From cb56d5af3880b5c8dbb3903225d3d2413a9dba34 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Tue, 24 Aug 2021 16:27:26 +1000 Subject: [PATCH 1/6] Avoid redefinition of strcasecmp in mingw-w64 --- config.h.cmake.in | 4 ++-- configure.ac | 2 +- libdispatch/ncjson.c | 2 +- libdispatch/nclist.c | 2 +- ncgen/ncgen.h | 2 ++ 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config.h.cmake.in b/config.h.cmake.in index b7a4c0bfe8..622e094add 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -57,7 +57,7 @@ are set when opening a binary file on Windows. */ #define _OFF_T_DEFINED #endif - #ifdef _WIN32 + #if defined(_WIN32) && !defined(__MINGW32__) #ifndef strcasecmp #define strcasecmp _stricmp #endif @@ -656,7 +656,7 @@ with zip */ #cmakedefine uintptr_t unsigned long /* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #ifndef HAVE_STRCASECMP #define strcasecmp _stricmp #endif diff --git a/configure.ac b/configure.ac index 2206b92256..eb91a064ac 100644 --- a/configure.ac +++ b/configure.ac @@ -1655,7 +1655,7 @@ AC_SUBST(HAS_LOGGING,[$enable_logging]) #AH_VERBATIM([_WIN32_STRICMP], AH_BOTTOM( [/* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strcasecmp _stricmp #define strncasecmp _strnicmp #define snprintf _snprintf diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 1cca2132ef..0ee47d940d 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -14,7 +14,7 @@ TODO: make utf8 safe #include #include "ncjson.h" -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strcasecmp _stricmp #else #include diff --git a/libdispatch/nclist.c b/libdispatch/nclist.c index 3d45d92a9d..83153db2e1 100644 --- a/libdispatch/nclist.c +++ b/libdispatch/nclist.c @@ -6,7 +6,7 @@ #include "nclist.h" -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strcasecmp _stricmp #endif diff --git a/ncgen/ncgen.h b/ncgen/ncgen.h index e93f4627b4..c2eac3a407 100644 --- a/ncgen/ncgen.h +++ b/ncgen/ncgen.h @@ -9,8 +9,10 @@ #ifdef _WIN32 #include #include "isnan.h" +#ifndef __MINGW32__ #define strcasecmp _stricmp #endif +#endif #ifdef USE_NETCDF4 #define CLASSICONLY 0 From 7b3d71b7189b4f81da812e144d6db9e0ab7cf531 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 5 Sep 2021 17:13:23 +1000 Subject: [PATCH 2/6] Define strcasecmp for Windows in ncconfigure.h --- include/ncconfigure.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/ncconfigure.h b/include/ncconfigure.h index 2b4375ea58..a12e4ab50c 100644 --- a/include/ncconfigure.h +++ b/include/ncconfigure.h @@ -65,13 +65,28 @@ extern int fileno(FILE*); #endif #endif /*STDC*/ -#endif /*!_WIN32*/ -#ifdef _WIN32 +#else /*_WIN32*/ + #ifndef HAVE_STRLCAT #define strlcat(d,s,n) strcat_s((d),(n),(s)) #endif + +#ifndef __MINGW32__ +#ifndef strcasecmp +#define strcasecmp _stricmp +#endif +#ifndef strncasecmp +#define strncasecmp _strnicmp #endif +#ifndef snprintf +#if _MSC_VER<1900 +#define snprintf _snprintf +#endif +#endif +#endif /*__MINGW32__*/ + +#endif /*_WIN32*/ /* handle null arguments */ #ifndef nulldup From 3cf75bf088c2e367f5af2f3f88bb85bf437f160d Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 5 Sep 2021 17:14:36 +1000 Subject: [PATCH 3/6] Avoid duplicate definition of strcasecmp in config.h --- config.h.cmake.in | 32 -------------------------------- configure.ac | 10 ---------- 2 files changed, 42 deletions(-) diff --git a/config.h.cmake.in b/config.h.cmake.in index 622e094add..276dfc202d 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -57,23 +57,6 @@ are set when opening a binary file on Windows. */ #define _OFF_T_DEFINED #endif - #if defined(_WIN32) && !defined(__MINGW32__) - #ifndef strcasecmp - #define strcasecmp _stricmp - #endif - - #ifndef strincasecmp - #define strncasecmp _strnicmp - #endif - - #ifndef snprintf - #if _MSC_VER<1900 - #define snprintf _snprintf - #endif - #endif - #endif - - #define strdup _strdup #define fdopen _fdopen #define write _write @@ -655,21 +638,6 @@ with zip */ /* Define to `unsigned long if does not define. */ #cmakedefine uintptr_t unsigned long -/* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#if defined(_WIN32) && !defined(__MINGW32__) - #ifndef HAVE_STRCASECMP - #define strcasecmp _stricmp - #endif - - #ifndef HAVE_STRNCASECMP - #define strncasecmp _strnicmp - #endif - - #ifndef HAVE_SNPRINTF - #define snprintf _snprintf - #endif -#endif - #cmakedefine WORDS_BIGENDIAN #include "ncconfigure.h" diff --git a/configure.ac b/configure.ac index eb91a064ac..e4cb3a2e49 100644 --- a/configure.ac +++ b/configure.ac @@ -1651,16 +1651,6 @@ AC_SUBST(HAS_MULTIFILTERS,[$has_multifilters]) AC_SUBST(DO_NCZARR_ZIP_TESTS,[$enable_nczarr_zip]) AC_SUBST(HAS_LOGGING,[$enable_logging]) -# Include some specifics for netcdf on windows. -#AH_VERBATIM([_WIN32_STRICMP], -AH_BOTTOM( -[/* Define strcasecmp, strncasecmp, snprintf on Win32 systems. */ -#if defined(_WIN32) && !defined(__MINGW32__) - #define strcasecmp _stricmp - #define strncasecmp _strnicmp - #define snprintf _snprintf -#endif]) - # Access netcdf specific version of config.h AH_BOTTOM([#include "ncconfigure.h"]) From 4fa91d824138b823241e5e6a31baecda30d618cd Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 5 Sep 2021 17:15:36 +1000 Subject: [PATCH 4/6] Use strcasecmp definitions from config.h --- dap4_test/dump.c | 1 - libdispatch/ncjson.c | 7 +------ libdispatch/nclist.c | 6 +----- ncdump/nccopy.c | 1 - ncdump/ncdump.c | 1 - ncdump/ncvalidator.c | 1 - ncgen/ncgen.h | 8 +------- ncgen3/main.c | 1 - 8 files changed, 3 insertions(+), 23 deletions(-) diff --git a/dap4_test/dump.c b/dap4_test/dump.c index 1c242f131f..76a49a5d54 100644 --- a/dap4_test/dump.c +++ b/dap4_test/dump.c @@ -17,7 +17,6 @@ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #include "netcdf.h" diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 0ee47d940d..12b9208ef3 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -12,14 +12,9 @@ TODO: make utf8 safe #include #include #include +#include "config.h" #include "ncjson.h" -#if defined(_WIN32) && !defined(__MINGW32__) -#define strcasecmp _stricmp -#else -#include -#endif - #undef DEBUG #define NCJ_OK 0 diff --git a/libdispatch/nclist.c b/libdispatch/nclist.c index 83153db2e1..a18c158ba5 100644 --- a/libdispatch/nclist.c +++ b/libdispatch/nclist.c @@ -3,13 +3,9 @@ #include #include #include - +#include "config.h" #include "nclist.h" -#if defined(_WIN32) && !defined(__MINGW32__) -#define strcasecmp _stricmp -#endif - int nclistnull(void* e) {return e == NULL;} #ifndef TRUE diff --git a/ncdump/nccopy.c b/ncdump/nccopy.c index 12f7592347..312f7dcca6 100644 --- a/ncdump/nccopy.c +++ b/ncdump/nccopy.c @@ -15,7 +15,6 @@ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #ifdef HAVE_UNISTD_H diff --git a/ncdump/ncdump.c b/ncdump/ncdump.c index f0cf351696..0321bc7c06 100644 --- a/ncdump/ncdump.c +++ b/ncdump/ncdump.c @@ -11,7 +11,6 @@ Research/Unidata. See \ref copyright file for more info. */ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #ifdef HAVE_UNISTD_H diff --git a/ncdump/ncvalidator.c b/ncdump/ncvalidator.c index dead0d0368..7e77c76fbe 100644 --- a/ncdump/ncvalidator.c +++ b/ncdump/ncvalidator.c @@ -76,7 +76,6 @@ THIS SOFTWARE. #if defined(_WIN32) && !defined(__MINGW32__) #include #include "XGetopt.h" -#define snprintf _snprintf #endif #define X_ALIGN 4 diff --git a/ncgen/ncgen.h b/ncgen/ncgen.h index c2eac3a407..45b5bfe13e 100644 --- a/ncgen/ncgen.h +++ b/ncgen/ncgen.h @@ -6,13 +6,7 @@ * $Header: /upc/share/CVS/netcdf-3/ncgen/ncgen.h,v 1.18 2010/06/01 15:34:53 ed Exp $ *********************************************************************/ -#ifdef _WIN32 -#include -#include "isnan.h" -#ifndef __MINGW32__ -#define strcasecmp _stricmp -#endif -#endif +#include "config.h" #ifdef USE_NETCDF4 #define CLASSICONLY 0 diff --git a/ncgen3/main.c b/ncgen3/main.c index 6f9c5f5df9..aabcae6803 100644 --- a/ncgen3/main.c +++ b/ncgen3/main.c @@ -17,7 +17,6 @@ #if defined(_WIN32) && !defined(__MINGW32__) #include "XGetopt.h" -#define snprintf _snprintf #endif #include "netcdf.h" From 1fa3955226ecffcf90a22ec73e788d72ece4e2ae Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Mon, 6 Sep 2021 10:28:18 +1000 Subject: [PATCH 5/6] Remove config.h from ncjson.c and nclist.c --- libdispatch/ncjson.c | 7 ++++++- libdispatch/nclist.c | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 12b9208ef3..0ee47d940d 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -12,9 +12,14 @@ TODO: make utf8 safe #include #include #include -#include "config.h" #include "ncjson.h" +#if defined(_WIN32) && !defined(__MINGW32__) +#define strcasecmp _stricmp +#else +#include +#endif + #undef DEBUG #define NCJ_OK 0 diff --git a/libdispatch/nclist.c b/libdispatch/nclist.c index a18c158ba5..83153db2e1 100644 --- a/libdispatch/nclist.c +++ b/libdispatch/nclist.c @@ -3,9 +3,13 @@ #include #include #include -#include "config.h" + #include "nclist.h" +#if defined(_WIN32) && !defined(__MINGW32__) +#define strcasecmp _stricmp +#endif + int nclistnull(void* e) {return e == NULL;} #ifndef TRUE From 114185e84bdfb408745a9e25ee4d6b3fdbc19976 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 3 Oct 2021 11:27:42 +1100 Subject: [PATCH 6/6] Fix NCJTHROW definition after merge from main --- libdispatch/ncjson.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libdispatch/ncjson.c b/libdispatch/ncjson.c index 32d459adc5..e862175648 100644 --- a/libdispatch/ncjson.c +++ b/libdispatch/ncjson.c @@ -15,8 +15,10 @@ TODO: make utf8 safe #include "ncjson.h" -#if defined(_WIN32) && !defined(__MINGW32__) -#define strcasecmp _stricmp +#undef NCJDEBUG +#ifdef NCJDEBUG +static int ncjbreakpoint(int err) {return err;} +#define NCJTHROW(err) ((err)==NCJ_ERR?ncjbreakpoint(err):(err)) #else #define NCJTHROW(err) (err) #endif @@ -60,7 +62,7 @@ typedef struct NCJbuf { /**************************************************/ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) #define strdup _strdup #define strcasecmp _stricmp #else