Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a number of OS specific bugs #2138

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This file contains a high-level description of this package's evolution. Release

## 4.8.2 - TBD

* [Bug Fix] Fix several os related errors. See [Github #2138](https://github.com/Unidata/netcdf-c/pull/2138).
* [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)
* [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)
* [Bug Fix] Fix string allocation error in H5FDhttp.c. See [Github #2127](https://github.com/Unidata/netcdf-c/pull/2127).
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,17 @@ case "`uname`" in
CYGWIN*) ISCYGWIN=yes;;
Darwin*) ISOSX=yes;;
WIN*) ISMSVC=yes;;
MINGW*) ISMINGW=yes;;
esac
AM_CONDITIONAL(ISCYGWIN, [test "x$ISCYGWIN" = xyes])
AM_CONDITIONAL(ISMSVC, [test "x$ISMSVC" = xyes])
AM_CONDITIONAL(ISOSX, [test "x$ISOSX" = xyes])
AM_CONDITIONAL(ISMINGW, [test "x$ISMINGW" = xyes])

AC_SUBST([ISMSVC], [${ISMSVC}])
AC_SUBST([ISCYGWIN], [${ISCYGWIN}])
AC_SUBST([ISOSX], [${ISOSX}])
AC_SUBST([ISMINGW], [${ISMINGW}])

###
# Crude hack to work around an issue
Expand Down
3 changes: 0 additions & 3 deletions include/ncconfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ extern long long int strtoll(const char*, char**, int);
#ifndef strtoull
extern unsigned long long int strtoull(const char*, char**, int);
#endif
#ifndef fileno
extern int fileno(FILE*);
#endif

#endif /*STDC*/
#endif /*!_WIN32*/
Expand Down
2 changes: 2 additions & 0 deletions include/ncrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and accessing rc files (e.g. .daprc).
/* getenv() keys */
#define NCRCENVIGNORE "NCRCENV_IGNORE"
#define NCRCENVRC "NCRCENV_RC"
#define NCRCENVHOME "NCRCENV_HOME"

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

/* Collect global state info in one place */
Expand Down
8 changes: 5 additions & 3 deletions libdispatch/dpathmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,12 @@ getlocalpathkind(void)
int kind = NCPD_UNKNOWN;
#ifdef __CYGWIN__
kind = NCPD_CYGWIN;
#elif __MSYS__
kind = NCPD_MSYS;
#elif _MSC_VER /* not _WIN32 */
#elif defined __MINGW32__
kind = NCPD_WIN;
#elif defined _MSC_VER /* not _WIN32 */
kind = NCPD_WIN;
#elif defined __MSYS__
kind = NCPD_MSYS;
#else
kind = NCPD_NIX;
#endif
Expand Down
25 changes: 21 additions & 4 deletions libdispatch/drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ ncrc_initialize(void)
}
}

static void
ncrc_setrchome(void)
{
const char* tmp = NULL;
if(ncrc_globalstate->rcinfo.rchome) return;
assert(ncrc_globalstate && ncrc_globalstate->home);
tmp = getenv(NCRCENVHOME);
if(tmp == NULL || strlen(tmp) == 0)
tmp = ncrc_globalstate->home;
ncrc_globalstate->rcinfo.rchome = strdup(tmp);
}

/* Get global state */
NCRCglobalstate*
ncrc_getglobalstate(void)
Expand Down Expand Up @@ -155,6 +167,7 @@ NC_rcclear(NCRCinfo* info)
{
if(info == NULL) return;
nullfree(info->rcfile);
nullfree(info->rchome);
rcfreeentries(info->entries);
}

Expand Down Expand Up @@ -193,9 +206,9 @@ NC_rcload(void)
/* locate the configuration files in order of use:
1. Specified by NCRCENV_RC environment variable.
2. If NCRCENV_RC is not set then merge the set of rc files in this order:
1. $HOME/.ncrc
2. $HOME/.daprc
3. $HOME/.docsrc
1. $RCHOME/.ncrc
2. $RCHOME/.daprc
3. $RCHOME/.docsrc
4. $CWD/.ncrc
5. $CWD/.daprc
6. $CWD/.docsrc
Expand All @@ -208,7 +221,11 @@ NC_rcload(void)
const char* dirnames[3];
const char** dir;

dirnames[0] = globalstate->home;

/* Make sure rcinfo.rchome is defined */
ncrc_setrchome();

dirnames[0] = globalstate->rcinfo.rchome;
dirnames[1] = globalstate->cwd;
dirnames[2] = NULL;

Expand Down
7 changes: 6 additions & 1 deletion libdispatch/dutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ NC_writefile(const char* filename, size_t size, void* content)
void* p;
size_t remain;

if(content == NULL) {content = ""; size = 0;}

#ifdef _WIN32
stream = NCfopen(filename,"wb");
#else
Expand Down Expand Up @@ -343,7 +345,8 @@ NC_testmode(NCURI* uri, const char* tag)
return found;
}

#ifdef __APPLE__
#if ! defined __INTEL_COMPILER
#if defined __APPLE__
int isinf(double x)
{
union { unsigned long long u; double f; } ieee754;
Expand All @@ -361,6 +364,8 @@ int isnan(double x)
}

#endif /*APPLE*/
#endif /*!_INTEL_COMPILER*/


int
NC_split_delim(const char* arg, char delim, NClist* segments)
Expand Down
70 changes: 10 additions & 60 deletions libsrc/memio.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "nc3internal.h"
#include "netcdf_mem.h"
#include "ncpathmgr.h"
#include "ncrc.h"
#include "ncbytes.h"

#undef DEBUG

Expand Down Expand Up @@ -710,48 +712,16 @@ readfile(const char* path, NC_memio* memio)
{
int status = NC_NOERR;
FILE* f = NULL;
size_t filesize = 0;
size_t count = 0;
char* memory = NULL;
char* p = NULL;

/* Open the file for reading */
#ifdef _MSC_VER
f = NCfopen(path,"rb");
#else
f = NCfopen(path,"r");
#endif
if(f == NULL)
{status = errno; goto done;}
/* get current filesize */
if(fseek(f,0,SEEK_END) < 0)
{status = errno; goto done;}
filesize = (size_t)ftell(f);
/* allocate memory */
memory = malloc((size_t)filesize);
if(memory == NULL)
{status = NC_ENOMEM; goto done;}
/* move pointer back to beginning of file */
rewind(f);
count = filesize;
p = memory;
while(count > 0) {
size_t actual;
actual = fread(p,1,count,f);
if(actual == 0 || ferror(f))
{status = NC_EIO; goto done;}
count -= actual;
p += actual;
}
NCbytes* buf = ncbytesnew();

if((status = NC_readfile(path,buf))) goto done;
if(memio) {
memio->size = (size_t)filesize;
memio->memory = memory;
memory = NULL;
memio->size = ncbyteslength(buf);
memio->memory = ncbytesextract(buf);
}

done:
if(memory != NULL)
free(memory);
ncbytesfree(buf);
if(f != NULL) fclose(f);
return status;
}
Expand All @@ -761,30 +731,10 @@ static int
writefile(const char* path, NCMEMIO* memio)
{
int status = NC_NOERR;
FILE* f = NULL;
size_t count = 0;
char* p = NULL;

/* Open/create the file for writing*/
#ifdef _MSC_VER
f = NCfopen(path,"wb");
#else
f = NCfopen(path,"w");
#endif
if(f == NULL)
{status = errno; goto done;}
rewind(f);
count = memio->size;
p = memio->memory;
while(count > 0) {
size_t actual;
actual = fwrite(p,1,count,f);
if(actual == 0 || ferror(f))
{status = NC_EIO; goto done;}
count -= actual;
p += actual;
if(memio) {
if((status = NC_writefile(path,memio->size,memio->memory))) goto done;
}
done:
if(f != NULL) fclose(f);
return status;
}
51 changes: 29 additions & 22 deletions ncdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ endif()
SET_TARGET_PROPERTIES(nctrunc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE
${CMAKE_CURRENT_BINARY_DIR})

IF(RCMERGE)
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR})
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
${CMAKE_CURRENT_BINARY_DIR})
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
endif()
IF(RCMERGE)
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR})
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG
${CMAKE_CURRENT_BINARY_DIR})
SET_TARGET_PROPERTIES(tst_rcmerge PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
endif()

IF(USE_HDF5)
SET_TARGET_PROPERTIES(tst_fileinfo PROPERTIES RUNTIME_OUTPUT_DIRECTORY
Expand All @@ -189,7 +189,6 @@ endif()
add_sh_test(ncdump tst_64bit)
add_bin_test_no_prefix(ref_ctest)
add_bin_test_no_prefix(ref_ctest64)
add_sh_test(ncdump tst_output)
add_sh_test(ncdump tst_lengths)
add_sh_test(ncdump tst_calendars)
build_bin_test_no_prefix(tst_utf8)
Expand All @@ -200,15 +199,21 @@ endif()
add_sh_test(ncdump tst_hdf5_offset)
ENDIF(USE_HDF5)

IF(NOT MSVC AND NOT MINGW)
add_sh_test(ncdump tst_output)
ENDIF()

add_sh_test(ncdump tst_null_byte_padding)
IF(USE_STRICT_NULL_BYTE_HEADER_PADDING)
SET_TESTS_PROPERTIES(ncdump_tst_null_byte_padding PROPERTIES WILL_FAIL TRUE)
ENDIF(USE_STRICT_NULL_BYTE_HEADER_PADDING)

add_sh_test(ncdump tst_nccopy3)
IF(HAVE_BASH)
SET_TESTS_PROPERTIES(ncdump_tst_nccopy3 PROPERTIES RUN_SERIAL TRUE)
ENDIF(HAVE_BASH)
IF(NOT MSVC AND NOT MINGW)
add_sh_test(ncdump tst_nccopy3)
IF(HAVE_BASH)
SET_TESTS_PROPERTIES(ncdump_tst_nccopy3 PROPERTIES RUN_SERIAL TRUE)
ENDIF(HAVE_BASH)
ENDIF()

add_sh_test(ncdump tst_nccopy3_subset)
add_sh_test(ncdump tst_charfill)
Expand Down Expand Up @@ -256,10 +261,11 @@ endif()
# formatting omits a 0.
###
IF(EXTRA_TESTS)
add_sh_test(ncdump run_back_comp_tests)
IF(MSVC)
SET_TESTS_PROPERTIES(ncdump_run_back_comp_tests PROPERTIES WILL_FAIL TRUE)
ENDIF(MSVC)
IF(USE_HDF5)
IF(NOT MSVC AND NOT MINGW)
add_sh_test(ncdump run_back_comp_tests)
ENDIF()
ENDIF()
ENDIF(EXTRA_TESTS)

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

add_sh_test(ncdump tst_netcdf4_4)
IF(MSVC AND HAVE_BASH)
SET_TESTS_PROPERTIES(ncdump_tst_netcdf4_4 PROPERTIES WILL_FAIL TRUE)
ENDIF(MSVC AND HAVE_BASH)
IF(HAVE_BASH)
IF(NOT MSVC AND NOT MINGW)
add_sh_test(ncdump tst_netcdf4_4)
ENDIF()
ENDIF(HAVE_BASH)

###
# Some test reordering was required to ensure these tests
Expand Down Expand Up @@ -324,11 +331,11 @@ endif()
IF(USE_HDF5)
IF(HAVE_BASH)
build_bin_test_no_prefix(tst_unicode)
IF(NOT MSVC)
IF(NOT MSVC AND NOT MINGW)
# These tests do not work under windows
add_sh_test(ncdump test_unicode_directory)
add_sh_test(ncdump test_unicode_path)
ENDIF(NOT MSVC)
ENDIF()
ENDIF(HAVE_BASH)
ENDIF(USE_HDF5)

Expand Down
Loading