Skip to content

Commit 33e4ec4

Browse files
authored
Merge pull request #2138 from DennisHeimbigner/fixosbugs.dmh
Fix a number of OS specific bugs
2 parents 0e205f9 + 6bd289d commit 33e4ec4

17 files changed

Lines changed: 162 additions & 144 deletions

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release
77

88
## 4.8.2 - TBD
99

10+
* [Bug Fix] Fix several os related errors. See [Github #2138](https://github.com/Unidata/netcdf-c/pull/2138).
1011
* [Enhancement] Support byte-range reading of netcdf-3 files stored in private buckets in S3. See [Github #2134](https://github.com/Unidata/netcdf-c/pull/2134)
1112
* [Enhancement] Support Amazon S3 access for NCZarr. Also support use of the existing Amazon SDK credentials system. See [Github #2114](https://github.com/Unidata/netcdf-c/pull/2114)
1213
* [Bug Fix] Fix string allocation error in H5FDhttp.c. See [Github #2127](https://github.com/Unidata/netcdf-c/pull/2127).

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,14 +1170,17 @@ case "`uname`" in
11701170
CYGWIN*) ISCYGWIN=yes;;
11711171
Darwin*) ISOSX=yes;;
11721172
WIN*) ISMSVC=yes;;
1173+
MINGW*) ISMINGW=yes;;
11731174
esac
11741175
AM_CONDITIONAL(ISCYGWIN, [test "x$ISCYGWIN" = xyes])
11751176
AM_CONDITIONAL(ISMSVC, [test "x$ISMSVC" = xyes])
11761177
AM_CONDITIONAL(ISOSX, [test "x$ISOSX" = xyes])
1178+
AM_CONDITIONAL(ISMINGW, [test "x$ISMINGW" = xyes])
11771179

11781180
AC_SUBST([ISMSVC], [${ISMSVC}])
11791181
AC_SUBST([ISCYGWIN], [${ISCYGWIN}])
11801182
AC_SUBST([ISOSX], [${ISOSX}])
1183+
AC_SUBST([ISMINGW], [${ISMINGW}])
11811184

11821185
###
11831186
# Crude hack to work around an issue

include/ncconfigure.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ extern long long int strtoll(const char*, char**, int);
6060
#ifndef strtoull
6161
extern unsigned long long int strtoull(const char*, char**, int);
6262
#endif
63-
#ifndef fileno
64-
extern int fileno(FILE*);
65-
#endif
6663

6764
#endif /*STDC*/
6865
#endif /*!_WIN32*/

include/ncrc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and accessing rc files (e.g. .daprc).
1919
/* getenv() keys */
2020
#define NCRCENVIGNORE "NCRCENV_IGNORE"
2121
#define NCRCENVRC "NCRCENV_RC"
22+
#define NCRCENVHOME "NCRCENV_HOME"
2223

2324
/* Known .aws profile keys */
2425
#define AWS_ACCESS_KEY_ID "aws_access_key_id"
@@ -38,6 +39,7 @@ typedef struct NCRCinfo {
3839
int loaded; /* 1 => already loaded */
3940
NClist* entries; /* the rc file entry store fields*/
4041
char* rcfile; /* specified rcfile; overrides anything else */
42+
char* rchome; /* Overrides $HOME when looking for .rc files */
4143
} NCRCinfo;
4244

4345
/* Collect global state info in one place */

libdispatch/dpathmgr.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,12 @@ getlocalpathkind(void)
871871
int kind = NCPD_UNKNOWN;
872872
#ifdef __CYGWIN__
873873
kind = NCPD_CYGWIN;
874-
#elif __MSYS__
875-
kind = NCPD_MSYS;
876-
#elif _MSC_VER /* not _WIN32 */
874+
#elif defined __MINGW32__
875+
kind = NCPD_WIN;
876+
#elif defined _MSC_VER /* not _WIN32 */
877877
kind = NCPD_WIN;
878+
#elif defined __MSYS__
879+
kind = NCPD_MSYS;
878880
#else
879881
kind = NCPD_NIX;
880882
#endif

libdispatch/drc.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ ncrc_initialize(void)
127127
}
128128
}
129129

130+
static void
131+
ncrc_setrchome(void)
132+
{
133+
const char* tmp = NULL;
134+
if(ncrc_globalstate->rcinfo.rchome) return;
135+
assert(ncrc_globalstate && ncrc_globalstate->home);
136+
tmp = getenv(NCRCENVHOME);
137+
if(tmp == NULL || strlen(tmp) == 0)
138+
tmp = ncrc_globalstate->home;
139+
ncrc_globalstate->rcinfo.rchome = strdup(tmp);
140+
}
141+
130142
/* Get global state */
131143
NCRCglobalstate*
132144
ncrc_getglobalstate(void)
@@ -155,6 +167,7 @@ NC_rcclear(NCRCinfo* info)
155167
{
156168
if(info == NULL) return;
157169
nullfree(info->rcfile);
170+
nullfree(info->rchome);
158171
rcfreeentries(info->entries);
159172
}
160173

@@ -193,9 +206,9 @@ NC_rcload(void)
193206
/* locate the configuration files in order of use:
194207
1. Specified by NCRCENV_RC environment variable.
195208
2. If NCRCENV_RC is not set then merge the set of rc files in this order:
196-
1. $HOME/.ncrc
197-
2. $HOME/.daprc
198-
3. $HOME/.docsrc
209+
1. $RCHOME/.ncrc
210+
2. $RCHOME/.daprc
211+
3. $RCHOME/.docsrc
199212
4. $CWD/.ncrc
200213
5. $CWD/.daprc
201214
6. $CWD/.docsrc
@@ -208,7 +221,11 @@ NC_rcload(void)
208221
const char* dirnames[3];
209222
const char** dir;
210223

211-
dirnames[0] = globalstate->home;
224+
225+
/* Make sure rcinfo.rchome is defined */
226+
ncrc_setrchome();
227+
228+
dirnames[0] = globalstate->rcinfo.rchome;
212229
dirnames[1] = globalstate->cwd;
213230
dirnames[2] = NULL;
214231

libdispatch/dutil.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ NC_writefile(const char* filename, size_t size, void* content)
256256
void* p;
257257
size_t remain;
258258

259+
if(content == NULL) {content = ""; size = 0;}
260+
259261
#ifdef _WIN32
260262
stream = NCfopen(filename,"wb");
261263
#else
@@ -343,7 +345,8 @@ NC_testmode(NCURI* uri, const char* tag)
343345
return found;
344346
}
345347

346-
#ifdef __APPLE__
348+
#if ! defined __INTEL_COMPILER
349+
#if defined __APPLE__
347350
int isinf(double x)
348351
{
349352
union { unsigned long long u; double f; } ieee754;
@@ -361,6 +364,8 @@ int isnan(double x)
361364
}
362365

363366
#endif /*APPLE*/
367+
#endif /*!_INTEL_COMPILER*/
368+
364369

365370
int
366371
NC_split_delim(const char* arg, char delim, NClist* segments)

libsrc/memio.c

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "nc3internal.h"
2929
#include "netcdf_mem.h"
3030
#include "ncpathmgr.h"
31+
#include "ncrc.h"
32+
#include "ncbytes.h"
3133

3234
#undef DEBUG
3335

@@ -710,48 +712,16 @@ readfile(const char* path, NC_memio* memio)
710712
{
711713
int status = NC_NOERR;
712714
FILE* f = NULL;
713-
size_t filesize = 0;
714-
size_t count = 0;
715-
char* memory = NULL;
716-
char* p = NULL;
717-
718-
/* Open the file for reading */
719-
#ifdef _MSC_VER
720-
f = NCfopen(path,"rb");
721-
#else
722-
f = NCfopen(path,"r");
723-
#endif
724-
if(f == NULL)
725-
{status = errno; goto done;}
726-
/* get current filesize */
727-
if(fseek(f,0,SEEK_END) < 0)
728-
{status = errno; goto done;}
729-
filesize = (size_t)ftell(f);
730-
/* allocate memory */
731-
memory = malloc((size_t)filesize);
732-
if(memory == NULL)
733-
{status = NC_ENOMEM; goto done;}
734-
/* move pointer back to beginning of file */
735-
rewind(f);
736-
count = filesize;
737-
p = memory;
738-
while(count > 0) {
739-
size_t actual;
740-
actual = fread(p,1,count,f);
741-
if(actual == 0 || ferror(f))
742-
{status = NC_EIO; goto done;}
743-
count -= actual;
744-
p += actual;
745-
}
715+
NCbytes* buf = ncbytesnew();
716+
717+
if((status = NC_readfile(path,buf))) goto done;
746718
if(memio) {
747-
memio->size = (size_t)filesize;
748-
memio->memory = memory;
749-
memory = NULL;
719+
memio->size = ncbyteslength(buf);
720+
memio->memory = ncbytesextract(buf);
750721
}
751722

752723
done:
753-
if(memory != NULL)
754-
free(memory);
724+
ncbytesfree(buf);
755725
if(f != NULL) fclose(f);
756726
return status;
757727
}
@@ -761,30 +731,10 @@ static int
761731
writefile(const char* path, NCMEMIO* memio)
762732
{
763733
int status = NC_NOERR;
764-
FILE* f = NULL;
765-
size_t count = 0;
766-
char* p = NULL;
767734

768-
/* Open/create the file for writing*/
769-
#ifdef _MSC_VER
770-
f = NCfopen(path,"wb");
771-
#else
772-
f = NCfopen(path,"w");
773-
#endif
774-
if(f == NULL)
775-
{status = errno; goto done;}
776-
rewind(f);
777-
count = memio->size;
778-
p = memio->memory;
779-
while(count > 0) {
780-
size_t actual;
781-
actual = fwrite(p,1,count,f);
782-
if(actual == 0 || ferror(f))
783-
{status = NC_EIO; goto done;}
784-
count -= actual;
785-
p += actual;
735+
if(memio) {
736+
if((status = NC_writefile(path,memio->size,memio->memory))) goto done;
786737
}
787738
done:
788-
if(f != NULL) fclose(f);
789739
return status;
790740
}

ncdump/CMakeLists.txt

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ endif()
160160
SET_TARGET_PROPERTIES(nctrunc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE
161161
${CMAKE_CURRENT_BINARY_DIR})
162162

163-
IF(RCMERGE)
164-
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY
165-
${CMAKE_CURRENT_BINARY_DIR})
166-
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
167-
${CMAKE_CURRENT_BINARY_DIR})
168-
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
169-
endif()
163+
IF(RCMERGE)
164+
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY
165+
${CMAKE_CURRENT_BINARY_DIR})
166+
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
167+
${CMAKE_CURRENT_BINARY_DIR})
168+
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
169+
endif()
170170

171171
IF(USE_HDF5)
172172
SET_TARGET_PROPERTIES(tst_fileinfo PROPERTIES RUNTIME_OUTPUT_DIRECTORY
@@ -189,7 +189,6 @@ endif()
189189
add_sh_test(ncdump tst_64bit)
190190
add_bin_test_no_prefix(ref_ctest)
191191
add_bin_test_no_prefix(ref_ctest64)
192-
add_sh_test(ncdump tst_output)
193192
add_sh_test(ncdump tst_lengths)
194193
add_sh_test(ncdump tst_calendars)
195194
build_bin_test_no_prefix(tst_utf8)
@@ -200,15 +199,21 @@ endif()
200199
add_sh_test(ncdump tst_hdf5_offset)
201200
ENDIF(USE_HDF5)
202201

202+
IF(NOT MSVC AND NOT MINGW)
203+
add_sh_test(ncdump tst_output)
204+
ENDIF()
205+
203206
add_sh_test(ncdump tst_null_byte_padding)
204207
IF(USE_STRICT_NULL_BYTE_HEADER_PADDING)
205208
SET_TESTS_PROPERTIES(ncdump_tst_null_byte_padding PROPERTIES WILL_FAIL TRUE)
206209
ENDIF(USE_STRICT_NULL_BYTE_HEADER_PADDING)
207210

208-
add_sh_test(ncdump tst_nccopy3)
209-
IF(HAVE_BASH)
210-
SET_TESTS_PROPERTIES(ncdump_tst_nccopy3 PROPERTIES RUN_SERIAL TRUE)
211-
ENDIF(HAVE_BASH)
211+
IF(NOT MSVC AND NOT MINGW)
212+
add_sh_test(ncdump tst_nccopy3)
213+
IF(HAVE_BASH)
214+
SET_TESTS_PROPERTIES(ncdump_tst_nccopy3 PROPERTIES RUN_SERIAL TRUE)
215+
ENDIF(HAVE_BASH)
216+
ENDIF()
212217

213218
add_sh_test(ncdump tst_nccopy3_subset)
214219
add_sh_test(ncdump tst_charfill)
@@ -256,10 +261,11 @@ endif()
256261
# formatting omits a 0.
257262
###
258263
IF(EXTRA_TESTS)
259-
add_sh_test(ncdump run_back_comp_tests)
260-
IF(MSVC)
261-
SET_TESTS_PROPERTIES(ncdump_run_back_comp_tests PROPERTIES WILL_FAIL TRUE)
262-
ENDIF(MSVC)
264+
IF(USE_HDF5)
265+
IF(NOT MSVC AND NOT MINGW)
266+
add_sh_test(ncdump run_back_comp_tests)
267+
ENDIF()
268+
ENDIF()
263269
ENDIF(EXTRA_TESTS)
264270

265271
# Known failure on MSVC; the number of 0's padding
@@ -272,10 +278,11 @@ endif()
272278
build_bin_test_no_prefix(tst_fillbug)
273279
add_sh_test(ncdump_sh tst_fillbug)
274280

275-
add_sh_test(ncdump tst_netcdf4_4)
276-
IF(MSVC AND HAVE_BASH)
277-
SET_TESTS_PROPERTIES(ncdump_tst_netcdf4_4 PROPERTIES WILL_FAIL TRUE)
278-
ENDIF(MSVC AND HAVE_BASH)
281+
IF(HAVE_BASH)
282+
IF(NOT MSVC AND NOT MINGW)
283+
add_sh_test(ncdump tst_netcdf4_4)
284+
ENDIF()
285+
ENDIF(HAVE_BASH)
279286

280287
###
281288
# Some test reordering was required to ensure these tests
@@ -324,11 +331,11 @@ endif()
324331
IF(USE_HDF5)
325332
IF(HAVE_BASH)
326333
build_bin_test_no_prefix(tst_unicode)
327-
IF(NOT MSVC)
334+
IF(NOT MSVC AND NOT MINGW)
328335
# These tests do not work under windows
329336
add_sh_test(ncdump test_unicode_directory)
330337
add_sh_test(ncdump test_unicode_path)
331-
ENDIF(NOT MSVC)
338+
ENDIF()
332339
ENDIF(HAVE_BASH)
333340
ENDIF(USE_HDF5)
334341

0 commit comments

Comments
 (0)