diff --git a/include/netcdf.h b/include/netcdf.h index 6ba8ba48be..3dfcb7ae21 100644 --- a/include/netcdf.h +++ b/include/netcdf.h @@ -17,7 +17,7 @@ See \ref copyright file for more info. #include /* netcdf functions sometimes return system errors */ /* Required for alloca on Windows */ -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) #include #endif diff --git a/include/onstack.h b/include/onstack.h index bd3b8e39e9..578495d563 100644 --- a/include/onstack.h +++ b/include/onstack.h @@ -63,7 +63,7 @@ # define FREE_ONSTACK(name) -#elif defined(_WIN32) || defined(_WIN64) +#elif defined(_WIN32) #include #undef ALLOCA_ARG_T # define ALLOCA_ARG_T size_t diff --git a/libdap4/d4util.c b/libdap4/d4util.c index 9a966cb469..ad02a265e4 100644 --- a/libdap4/d4util.c +++ b/libdap4/d4util.c @@ -381,7 +381,7 @@ NCD4_mktmp(const char* base, char** tmpnamep) if(rno < 0) rno = -rno; snprintf(spid,sizeof(spid),"%06d",rno); strncat(tmp,spid,sizeof(tmp)); -#if defined(_WIN32) || defined(_WIN64) +#ifdef _WIN32 fd=open(tmp,O_RDWR|O_BINARY|O_CREAT, _S_IREAD|_S_IWRITE); # else fd=open(tmp,O_RDWR|O_CREAT|O_EXCL, S_IRWXU); diff --git a/libdap4/ncd4dispatch.c b/libdap4/ncd4dispatch.c index 9dc764a7ce..e59d74882d 100644 --- a/libdap4/ncd4dispatch.c +++ b/libdap4/ncd4dispatch.c @@ -6,7 +6,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#if defined(_WIN32) || defined(_WIN64) +#ifdef _WIN32 #include #include #endif diff --git a/libdispatch/ddispatch.c b/libdispatch/ddispatch.c index 81e8506a55..edccac6bca 100644 --- a/libdispatch/ddispatch.c +++ b/libdispatch/ddispatch.c @@ -61,7 +61,7 @@ NCDISPATCH_initialize(void) char* p; char* q; char cwd[4096]; -#ifdef _MSC_VER +#ifdef _WIN32 tempdir = getenv("TEMP"); #else tempdir = "/tmp"; diff --git a/libdispatch/dfile.c b/libdispatch/dfile.c index 72d424a43c..6eab9d84f3 100644 --- a/libdispatch/dfile.c +++ b/libdispatch/dfile.c @@ -2178,3 +2178,169 @@ nc__pseudofd(void) } return pseudofd++; } + +/** +\internal +\ingroup datasets +Provide open, read and close for use when searching for magic numbers +*/ +static int +openmagic(struct MagicFile* file) +{ + int status = NC_NOERR; + assert((!file->diskless && file->inmemory) ? file->parameters != NULL : 1); + if(file->inmemory && !file->diskless) { + /* Get its length */ + NC_memio* meminfo = (NC_memio*)file->parameters; + file->filelen = (long long)meminfo->size; + goto done; + } +#ifdef USE_PARALLEL + if (file->use_parallel) { + int retval; + MPI_Offset size; + assert(file->parameters); + if((retval = MPI_File_open(((NC_MPI_INFO*)file->parameters)->comm, + (char*)file->path,MPI_MODE_RDONLY, + ((NC_MPI_INFO*)file->parameters)->info, + &file->fh)) != MPI_SUCCESS) + {status = NC_EPARINIT; goto done;} + /* Get its length */ + if((retval=MPI_File_get_size(file->fh, &size)) != MPI_SUCCESS) + {status = NC_EPARINIT; goto done;} + file->filelen = (long long)size; + goto done; + } +#endif /* USE_PARALLEL */ + { + if(file->path == NULL || strlen(file->path)==0) + {status = NC_EINVAL; goto done;} +#ifdef _WIN32 + file->fp = fopen(file->path, "rb"); +#else + file->fp = fopen(file->path, "r"); +#endif + if(file->fp == NULL) + {status = errno; goto done;} + /* Get its length */ + { + int fd = fileno(file->fp); +#ifdef _MSC_VER + __int64 len64 = _filelengthi64(fd); + if(len64 < 0) + {status = errno; goto done;} + file->filelen = (long long)len64; +#else + off_t size; + size = lseek(fd, 0, SEEK_END); + if(size == -1) + {status = errno; goto done;} + file->filelen = (long long)size; +#endif + rewind(file->fp); + } + goto done; + } + +done: + return status; +} + +static int +readmagic(struct MagicFile* file, long pos, char* magic) +{ + int status = NC_NOERR; + memset(magic,0,MAGIC_NUMBER_LEN); + if(file->inmemory && !file->diskless) { + char* mempos; + NC_memio* meminfo = (NC_memio*)file->parameters; + if((pos + MAGIC_NUMBER_LEN) > meminfo->size) + {status = NC_EDISKLESS; goto done;} + mempos = ((char*)meminfo->memory) + pos; + memcpy((void*)magic,mempos,MAGIC_NUMBER_LEN); +#ifdef DEBUG + printmagic("XXX: readmagic",magic,file); +#endif + goto done; + } +#ifdef USE_PARALLEL + if (file->use_parallel) { + MPI_Status mstatus; + int retval; + if((retval = MPI_File_read_at_all(file->fh, pos, magic, + MAGIC_NUMBER_LEN, MPI_CHAR, &mstatus)) != MPI_SUCCESS) + {status = NC_EPARINIT; goto done;} + goto done; + } +#endif /* USE_PARALLEL */ + { + int count; + int i = fseek(file->fp,pos,SEEK_SET); + if(i < 0) + {status = errno; goto done;} + for(i=0;ifp); + if(count == 0 || ferror(file->fp)) + {status = errno; goto done;} + i += count; + } + goto done; + } +done: + if(file && file->fp) clearerr(file->fp); + return status; +} + +/** + * Close the file opened to check for magic number. + * + * @param file pointer to the MagicFile struct for this open file. + * @returns NC_NOERR for success + * @returns NC_EPARINIT if there was a problem closing file with MPI + * (parallel builds only). + * @author Dennis Heimbigner + */ +static int +closemagic(struct MagicFile* file) +{ + int status = NC_NOERR; + if(file->inmemory) goto done; /* noop*/ +#ifdef USE_PARALLEL + if (file->use_parallel) { + int retval; + if((retval = MPI_File_close(&file->fh)) != MPI_SUCCESS) + {status = NC_EPARINIT; goto done;} + goto done; + } +#endif + { + if(file->fp) fclose(file->fp); + goto done; + } +done: + return status; +} + +#ifdef DEBUG +static void +printmagic(const char* tag, char* magic, struct MagicFile* f) +{ + int i; + fprintf(stderr,"%s: inmem=%d ispar=%d magic=",tag,f->inmemory,f->use_parallel); + for(i=0;i #include #include @@ -146,7 +146,7 @@ static size_t pagesize(void) { size_t pgsz; -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) SYSTEM_INFO info; #endif /* Hmm, aren't standards great? */ @@ -155,7 +155,7 @@ pagesize(void) #endif /* For MinGW Builds */ -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) GetSystemInfo(&info); pgsz = (size_t)info.dwPageSize; #elif defined(_SC_PAGESIZE) diff --git a/nc_test/test_read.m4 b/nc_test/test_read.m4 index 4434d6d312..02a3e9f24a 100644 --- a/nc_test/test_read.m4 +++ b/nc_test/test_read.m4 @@ -19,7 +19,7 @@ dnl (MPI_Offset vs. size_t), and function name substrings for external data dnl types. dnl -#if defined (_WIN32) || defined (_WIN64) +#ifdef _WIN32 #include #endif diff --git a/nc_test/test_write.m4 b/nc_test/test_write.m4 index 4650e37067..a335a01559 100644 --- a/nc_test/test_write.m4 +++ b/nc_test/test_write.m4 @@ -19,7 +19,7 @@ dnl (MPI_Offset vs. size_t), and function name substrings for external data dnl types. dnl -#if defined (_WIN32) || defined (_WIN64) +#ifdef _WIN32 #include #endif diff --git a/nc_test/tst_diskless5.c b/nc_test/tst_diskless5.c index ab06f36df3..80c336de62 100644 --- a/nc_test/tst_diskless5.c +++ b/nc_test/tst_diskless5.c @@ -14,7 +14,7 @@ See \ref copyright file for more info. #include #include #include -#if defined (_WIN32) || defined (_WIN64) || defined _MSC_VER +#ifdef _WIN32 #include #else #include diff --git a/nc_test4/tst_atts1.c b/nc_test4/tst_atts1.c index b35a304a5f..87b3643c5b 100644 --- a/nc_test4/tst_atts1.c +++ b/nc_test4/tst_atts1.c @@ -352,7 +352,7 @@ main(int argc, char **argv) /* for (i = 0; i < ATT_LEN; i++) */ /* if (float_in[i] != (float) longlong_out[i]) ERR; */ if (nc_get_att_float(ncid, NC_GLOBAL, ATT_UINT64_NAME, float_in)) ERR; -#if !defined(_WIN32) && !defined(_WIN64) +#ifndef _WIN32 for (i = 0; i < ATT_LEN; i++) if (float_in[i] != (float) ulonglong_out[i]) ERR; #endif diff --git a/nc_test4/tst_udf.c b/nc_test4/tst_udf.c index ebe5437808..e976339291 100644 --- a/nc_test4/tst_udf.c +++ b/nc_test4/tst_udf.c @@ -15,7 +15,7 @@ #define FILE_NAME "tst_udf.nc" -#if defined(_WIN32) || defined(_WIN64) +#ifdef _WIN32 int NC4_show_metadata(int ncid) {