mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-25 17:40:27 +08:00
win32/mingw fixes
This commit is contained in:
parent
79c751b806
commit
4f68d6c5f8
@ -7,8 +7,12 @@
|
||||
#include "ncdap3.h"
|
||||
|
||||
#ifdef HAVE_GETRLIMIT
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
# ifdef HAVE_SYS_RESOURCE_H
|
||||
# include <sys/time.h>
|
||||
# endif
|
||||
# ifdef HAVE_SYS_RESOURCE_H
|
||||
# include <sys/resource.h>
|
||||
# endif
|
||||
#endif
|
||||
#include "dapdump.h"
|
||||
|
||||
|
@ -7,8 +7,12 @@
|
||||
#include "ncdap3.h"
|
||||
|
||||
#ifdef HAVE_GETRLIMIT
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
# ifdef HAVE_SYS_RESOURCE_H
|
||||
# include <sys/time.h>
|
||||
# endif
|
||||
# ifdef HAVE_SYS_RESOURCE_H
|
||||
# include <sys/resource.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "nc3dispatch.h"
|
||||
|
@ -1605,8 +1605,9 @@ nc__pseudofd(void)
|
||||
maxfd = rl.rlim_cur;
|
||||
}
|
||||
pseudofd = maxfd+1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return pseudofd++;
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,16 @@ nc_uriparse(const char* uri0, NC_URI** nc_urip)
|
||||
nc_uri = (NC_URI*)calloc(1,sizeof(NC_URI));
|
||||
if(nc_uri == NULL) return 0;
|
||||
|
||||
/* Temporary hack to remove escape characters inserted by Windows or MinGW */
|
||||
if(strchr(uri0,'\\') != NULL) {
|
||||
char* u = strdup(uri0);
|
||||
if(u == NULL) return 0;
|
||||
p = u;
|
||||
p1 = u;
|
||||
while((c=*p1++)) {if(c != '\\') *p++ = c;}
|
||||
uri0 = (const char*)u;
|
||||
}
|
||||
|
||||
/* make local copy of uri */
|
||||
uri = strdup(uri0);
|
||||
|
||||
|
@ -447,7 +447,11 @@ memio_close(ncio* nciop, int doUnlink)
|
||||
/* See if the user wants the contents persisted to a file */
|
||||
if(memio->persist) {
|
||||
/* Try to open the file for writing */
|
||||
fd = open(nciop->path, O_WRONLY|O_CREAT|O_TRUNC, OPENMODE);
|
||||
int oflags = O_WRONLY|O_CREAT|O_TRUNC;
|
||||
#ifdef O_BINARY
|
||||
fSet(oflags, O_BINARY);
|
||||
#endif
|
||||
fd = open(nciop->path, oflags, OPENMODE);
|
||||
if(fd >= 0) {
|
||||
/* We need to do multiple writes because there is no
|
||||
guarantee that the amount written will be the full amount */
|
||||
|
@ -24,12 +24,14 @@ extern int ffio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void**
|
||||
extern int ffio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
|
||||
#endif
|
||||
|
||||
#ifdef USE_MMAP
|
||||
extern int mmapio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
|
||||
extern int mmapio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
|
||||
#else
|
||||
extern int memio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
|
||||
extern int memio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
|
||||
#ifdef USE_DISKLESS
|
||||
# ifdef USE_MMAP
|
||||
extern int mmapio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
|
||||
extern int mmapio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
|
||||
# else
|
||||
extern int memio_create(const char*,int,size_t,off_t,size_t,size_t*,ncio**,void** const);
|
||||
extern int memio_open(const char*,int,off_t,size_t,size_t*,ncio**,void** const);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int
|
||||
@ -39,10 +41,12 @@ ncio_create(const char *path, int ioflags, size_t initialsz,
|
||||
{
|
||||
if(fIsSet(ioflags,NC_DISKLESS))
|
||||
|
||||
#ifdef USE_MMAP
|
||||
#ifdef USE_DISKLESS
|
||||
# ifdef USE_MMAP
|
||||
return mmapio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
#else
|
||||
# else
|
||||
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_FFIO
|
||||
@ -60,13 +64,15 @@ ncio_open(const char *path, int ioflags,
|
||||
/* Diskless open has the following constraints:
|
||||
1. file must be classic version 1 or 2
|
||||
*/
|
||||
#ifdef USE_DISKLESS
|
||||
if(fIsSet(ioflags,NC_DISKLESS)) {
|
||||
#ifdef USE_MMAP
|
||||
return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
#else
|
||||
return memio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
#endif
|
||||
# ifdef USE_MMAP
|
||||
return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
# else
|
||||
return memio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_FFIO
|
||||
return ffio_open(path,ioflags,igeto,igetsz,sizehintp,iopp,mempp);
|
||||
#else
|
||||
|
@ -302,6 +302,7 @@ main(int argc, char *argv[])
|
||||
else
|
||||
fprintf(stderr, "*** nc_test SUCCESS!!!\n");
|
||||
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,20 @@
|
||||
/* Global */
|
||||
int diskless = 0;
|
||||
|
||||
int status = NC_NOERR;
|
||||
|
||||
static void
|
||||
report(int status,int lineno)
|
||||
{
|
||||
if(status) {
|
||||
fprintf(stderr,"fail: line %d; %s\n",lineno,nc_strerror(status));
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
#undef ERR
|
||||
#define ERR report(status,__LINE__)
|
||||
|
||||
/* Test a diskless file with two record vars, which grow, and has
|
||||
* attributes added. */
|
||||
@ -50,11 +64,11 @@ test_two_growing_with_att(const char *testfile)
|
||||
int v, r;
|
||||
|
||||
/* Create a file with one ulimited dimensions, and one var. */
|
||||
if (nc_create(testfile, NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME2, NC_CHAR, 1, &dimid, &varid[1])) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
if((status=nc_create(testfile, NC_CLOBBER, &ncid))) ERR;
|
||||
if((status=nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid))) ERR;
|
||||
if((status=nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid[0]))) ERR;
|
||||
if((status=nc_def_var(ncid, VAR_NAME2, NC_CHAR, 1, &dimid, &varid[1]))) ERR;
|
||||
if((status=nc_close(ncid))) ERR;
|
||||
|
||||
/* Create some phoney data. */
|
||||
for (data[0] = 'a', r = 1; r < MAX_RECS; r++)
|
||||
@ -66,30 +80,31 @@ test_two_growing_with_att(const char *testfile)
|
||||
for (r = 0; r < MAX_RECS; r++)
|
||||
{
|
||||
/* Write one record of var data, a single character. */
|
||||
if (nc_open(testfile, NC_WRITE, &ncid)) ERR;
|
||||
if((status=nc_open(testfile, NC_WRITE, &ncid)))
|
||||
ERR;
|
||||
count[0] = 1;
|
||||
start[0] = r;
|
||||
sprintf(att_name, "a_%d", data[r]);
|
||||
for (v = 0; v < NUM_VARS; v++)
|
||||
{
|
||||
if (nc_put_vara_text(ncid, varid[v], start, count, &data[r])) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_put_att_text(ncid, varid[v], att_name, 1, &data[r])) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if((status=nc_put_vara_text(ncid, varid[v], start, count, &data[r]))) ERR;
|
||||
if((status=nc_redef(ncid))) ERR;
|
||||
if((status=nc_put_att_text(ncid, varid[v], att_name, 1, &data[r]))) ERR;
|
||||
if((status=nc_enddef(ncid))) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
if((status=nc_close(ncid))) ERR;
|
||||
|
||||
/* Reopen the file and check it. */
|
||||
if (nc_open(testfile, NC_DISKLESS|NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_dimlen(ncid, 0, &len_in)) ERR;
|
||||
if((status=nc_open(testfile, NC_DISKLESS|NC_WRITE, &ncid))) ERR;
|
||||
if((status=nc_inq_dimlen(ncid, 0, &len_in))) ERR;
|
||||
if (len_in != r + 1) ERR;
|
||||
index[0] = r;
|
||||
for (v = 0; v < NUM_VARS; v++)
|
||||
{
|
||||
if (nc_get_var1_text(ncid, varid[v], index, &data_in)) ERR;
|
||||
if((status=nc_get_var1_text(ncid, varid[v], index, &data_in))) ERR;
|
||||
if (data_in != data[r]) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
if((status=nc_close(ncid))) ERR;
|
||||
} /* Next record. */
|
||||
return 0;
|
||||
}
|
||||
@ -104,29 +119,29 @@ test_one_with_att(const char *testfile)
|
||||
size_t start[NDIMS], count[NDIMS];
|
||||
|
||||
/* Create a file with one ulimited dimensions, and one var. */
|
||||
if (nc_create(testfile, NC_CLOBBER, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid)) ERR;
|
||||
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_NAME, 1, &data)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if((status=nc_create(testfile, NC_CLOBBER, &ncid))) ERR;
|
||||
if((status=nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid))) ERR;
|
||||
if((status=nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid))) ERR;
|
||||
if((status=nc_put_att_text(ncid, NC_GLOBAL, ATT_NAME, 1, &data))) ERR;
|
||||
if((status=nc_enddef(ncid))) ERR;
|
||||
|
||||
/* Write one record of var data, a single character. */
|
||||
count[0] = 1;
|
||||
start[0] = 0;
|
||||
if (nc_put_vara_text(ncid, varid, start, count, &data)) ERR;
|
||||
if((status=nc_put_vara_text(ncid, varid, start, count, &data))) ERR;
|
||||
|
||||
/* We're done! */
|
||||
if (nc_close(ncid)) ERR;
|
||||
if((status=nc_close(ncid))) ERR;
|
||||
|
||||
/* Reopen the file and check it. */
|
||||
if (nc_open(testfile, NC_DISKLESS|NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if((status=nc_open(testfile, NC_DISKLESS|NC_WRITE, &ncid))) ERR;
|
||||
if((status=nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid))) ERR;
|
||||
if (ndims != 1 && nvars != 1 && natts != 0 && unlimdimid != 0) ERR;
|
||||
if (nc_get_var_text(ncid, varid, &data_in)) ERR;
|
||||
if((status=nc_get_var_text(ncid, varid, &data_in))) ERR;
|
||||
if (data_in != data) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in)) ERR;
|
||||
if((status=nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in))) ERR;
|
||||
if (data_in != data) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
if((status=nc_close(ncid))) ERR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
#ifdef HAVE_SYS_TIMES_H
|
||||
# include <sys/times.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h> /* for sysconf */
|
||||
#include <sys/resource.h>
|
||||
#ifdef HAVE_SYS_RESOURCE_H
|
||||
# include <sys/resource.h>
|
||||
#endif
|
||||
#include <nc_tests.h> /* The ERR macro is here... */
|
||||
#include <netcdf.h>
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
MSC_EXTRA extern int ncopts; /* netCDF error options */
|
||||
EXTERNL int ncopts; /* netCDF error options */
|
||||
char *testfiles[] = {"nonesuch", "nctest_classic.nc",
|
||||
"nctest_64bit_offset.nc", "nctest_netcdf4.nc"};
|
||||
char *testfile;
|
||||
|
Loading…
x
Reference in New Issue
Block a user