These changes were made in order to make compilation of netcdf with opendap capabilities possible under MINGW-MSYS2. I refer to the email conversation with ticket netCDF #JZZ-916731. The present pull request is changed from my earlier patches, based on your response. In particular, I have avoided use of the generic compilation flag WIN32 but made everything as specific and tailored to the functions involved as possible. This should not interfere with other builds than builds under MINGW (I hope).
The changes, per file, are as follows:
1. /libdispatch/dutil.c Correction of a typing error in the code. I bumped onto this, probably because something else in the compilation had gone wrong, so I am not sure that this correction is absolutely needed. However, it will also not harm to correct
2. CMakeLists.txt The changes in this file are as follows: (a) in a number of places changes for MSVC are also needed for MINGW. These changes were copied from an existing MSYS2 compilation recipe, but instead of using the flag WIN32 I made it more specific (MINGW) so as not to interfere with other compilation procedures (e.g. Cygwin or others). (b) In addition, I defined two new variables that are set both under MSVC and MINGW. HAVE_WIN_TEMP expresses the fact that one has to look for the tmp directory using the Windows environmental variable TEMP, and is used in /libdispatch/ddispatch.c; HAVE_WIN_SSCANF expresses the fact that the Windows runtime library is used for the sscanf function (this is done both by MSVC and by MINGW). In the Windows implementation of sscanf, two differences occur: the specifier %hhu is not recognized, and NaN is not recognized as a special character sequence but results in an error if one assigns to a float or double. The flag HAVE_WIN_SSCANF is used in the files /lbdap2/dapcvt.c and /ncgen/cvt.c
3. config.h.cmake.in is changed in order to set the compiler flags HAVE_WIN_TEMP and HAVE_WIN_SSCANF with #cmakedefine commands
4. ncconfigure.h is changed in order to solve a problem with strlcat. This function is not available under MINGW, and the alternative formulation that belongs to the netcdf source could not be linked to certain functions because strlcat was not exported to the dll. I have changed the header in such a way that this export happens, but only when HAVE_STRLCAT is undefined. It should change nothing to builds where the function is natively present.
Note one point where interference with other builds is, in principle, possible. Some changes in the use of sscanf under MSVC were made specific to a certain version of MSVC in the file dapcvt.c, while I have now set the flag HAVE_WIN_SSCANF generic for all versions of MSVC. I did this because I could not find back any documentation from Microsoft suggesting that sscanf had been changed and the lacking functionality added in later versions. In addition, I think it very unlikely that lack of functionality was only present in a single version, not in earlier or later ones. However, I am not entirely certain about this and it is a matter of consideration
Note, further, that I only made changes to the CMake system, not to the config/autoconfig system as I did not use that and do not know very well how it functions.
These changes were made in order to make compilation of netcdf with opendap capabilities possible under MINGW-MSYS2. I refer to the email conversation with ticket netCDF #JZZ-916731. The present pull request is changed from my earlier patches, based on your response. In particular, I have avoided use of the generic compilation flag WIN32 but made everything as specific and tailored to the functions involved as possible. This should not interfere with other builds than builds under MINGW (I hope).
The changes, per file, are as follows:
Note one point where interference with other builds is, in principle, possible. Some changes in the use of sscanf under MSVC were made specific to a certain version of MSVC in the file dapcvt.c, while I have now set the flag HAVE_WIN_SSCANF generic for all versions of MSVC. I did this because I could not find back any documentation from Microsoft suggesting that sscanf had been changed and the lacking functionality added in later versions. In addition, I think it very unlikely that lack of functionality was only present in a single version, not in earlier or later ones. However, I am not entirely certain about this and it is a matter of consideration
Note, further, that I only made changes to the CMake system, not to the config/autoconfig system as I did not use that and do not know very well how it functions.