mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
fixed bug GGL-730752
This commit is contained in:
parent
30ed1c1710
commit
99c572f664
35
oc/http.c
35
oc/http.c
@ -1,6 +1,5 @@
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@ -62,13 +61,16 @@ ocfetchurl_file(CURL* curl, char* url, FILE* stream,
|
||||
}
|
||||
|
||||
if (stat == OC_NOERR) {
|
||||
/* return the file size*/
|
||||
if (sizep != NULL)
|
||||
*sizep = fetchdata.size;
|
||||
/* Get the last modified time */
|
||||
if(filetime != NULL)
|
||||
cstat = curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime);
|
||||
if(cstat != CURLE_OK) goto fail;
|
||||
/* return the file size*/
|
||||
#ifdef OCDEBUG
|
||||
oc_log(LOGNOTE,"filesize: %lu bytes",fetchdata.size);
|
||||
#endif
|
||||
if (sizep != NULL)
|
||||
*sizep = fetchdata.size;
|
||||
/* Get the last modified time */
|
||||
if(filetime != NULL)
|
||||
cstat = curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime);
|
||||
if(cstat != CURLE_OK) goto fail;
|
||||
}
|
||||
return THROW(stat);
|
||||
|
||||
@ -119,6 +121,9 @@ ocfetchurl(CURL* curl, char* url, OCbytes* buf, long* filetime)
|
||||
len = ocbyteslength(buf);
|
||||
ocbytesappend(buf, '\0');
|
||||
ocbytessetlength(buf, len); /* dont count null in buffer size*/
|
||||
#ifdef OCDEBUG
|
||||
oc_log(LOGNOTE,"buffersize: %lu bytes",(unsigned long)ocbyteslength(buf));
|
||||
#endif
|
||||
|
||||
return THROW(stat);
|
||||
|
||||
@ -130,15 +135,20 @@ fail:
|
||||
static size_t
|
||||
WriteFileCallback(void* ptr, size_t size, size_t nmemb, void* data)
|
||||
{
|
||||
size_t realsize = size * nmemb;
|
||||
size_t count;
|
||||
struct Fetchdata* fetchdata;
|
||||
fetchdata = (struct Fetchdata*) data;
|
||||
if(realsize == 0)
|
||||
oc_log(LOGWARN,"WriteFileCallback: zero sized chunk");
|
||||
count = fwrite(ptr, size, nmemb, fetchdata->stream);
|
||||
if (count > 0) {
|
||||
fetchdata->size += (count * size);
|
||||
} else {
|
||||
oc_log(LOGWARN,"WriteFileCallback: zero sized write");
|
||||
}
|
||||
#ifdef OCPROGRESS
|
||||
oc_log(LOGNOTE,"callback: %lu bytes",(unsigned long)(size*nmemb));
|
||||
oc_log(LOGNOTE,"callback: %lu bytes",(unsigned long)realsize);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
@ -148,14 +158,17 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
{
|
||||
size_t realsize = size * nmemb;
|
||||
OCbytes* buf = (OCbytes*) data;
|
||||
if(realsize == 0)
|
||||
oc_log(LOGWARN,"WriteMemoryCallback: zero sized chunk");
|
||||
if(realsize == 0)
|
||||
oc_log(LOGWARN,"WriteMemoryCallback: zero sized chunk");
|
||||
/* Optimize for reading potentially large dods datasets */
|
||||
if(!ocbytesavail(buf,realsize)) {
|
||||
/* double the size of the packet */
|
||||
ocbytessetalloc(buf,2*ocbytesalloc(buf));
|
||||
}
|
||||
ocbytesappendn(buf, ptr, realsize);
|
||||
#ifdef OCPROGRESS
|
||||
oc_log(LOGNOTE,"callback: %lu bytes",(unsigned long)realsize);
|
||||
#endif
|
||||
return realsize;
|
||||
}
|
||||
|
||||
|
@ -552,6 +552,7 @@ ocarraycount(OCstate* state, OCcontent* content)
|
||||
|
||||
/* Otherwise verify against xdr */
|
||||
xdrs = content->tree->data.xdrs;
|
||||
|
||||
OCASSERT((xdrs != NULL));
|
||||
|
||||
/* checkpoint current location */
|
||||
|
@ -7,13 +7,15 @@
|
||||
#include <stdarg.h>
|
||||
#include "ocdump.h"
|
||||
|
||||
#define OCDEBUG 1
|
||||
|
||||
/* OCCATCHERROR is used to detect errors as close
|
||||
to their point of origin as possible. When
|
||||
enabled, one can set a breakpoint in ocbreakpoint()
|
||||
to catch the failure. Turing it on incurs a significant
|
||||
performance penalty, so it is off by default.*/
|
||||
|
||||
#undef OCCATCHERROR
|
||||
#define OCCATCHERROR
|
||||
|
||||
#define OCPANIC(msg) assert(ocpanic(msg))
|
||||
#define OCPANIC1(msg,arg) assert(ocpanic(msg,arg))
|
||||
|
18
oc/ocdump.c
18
oc/ocdump.c
@ -1,6 +1,8 @@
|
||||
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
||||
See the COPYRIGHT file for more information. */
|
||||
|
||||
#define CRUDE
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef NETINET_IN_H
|
||||
@ -241,10 +243,13 @@ dumpmem1(int index, unsigned int n, unsigned int n1)
|
||||
} dform;
|
||||
form.uv = n;
|
||||
s[0] = '\0';
|
||||
#ifndef CRUDE
|
||||
sprintf(tmp,"%6d",index);
|
||||
dumpmem2(tmp,s,5);
|
||||
#endif
|
||||
sprintf(tmp,"%08x",form.uv);
|
||||
dumpmem2(tmp,s,8);
|
||||
#ifndef CRUDE
|
||||
sprintf(tmp,"%12u",form.uv);
|
||||
dumpmem2(tmp,s,12);
|
||||
sprintf(tmp,"%12d",form.sv);
|
||||
@ -265,6 +270,9 @@ dumpmem1(int index, unsigned int n, unsigned int n1)
|
||||
dform.uv[0] = n1;
|
||||
sprintf(tmp,"%#g",dform.dv);
|
||||
dumpmem2(tmp,s,12);
|
||||
#else
|
||||
tmp[0] = '\0';
|
||||
#endif
|
||||
strcat(s,"\n");
|
||||
fprintf(stderr,"%s",s);
|
||||
}
|
||||
@ -278,6 +286,7 @@ dumpmemory0(char* memory, int len, int fromxdr, int bod)
|
||||
|
||||
assert(memory[len] == 0);
|
||||
|
||||
#ifndef CRUDE
|
||||
/* build the header*/
|
||||
hdr[0] = '\0';
|
||||
dumpmem2("offset",hdr,6);
|
||||
@ -289,6 +298,7 @@ dumpmemory0(char* memory, int len, int fromxdr, int bod)
|
||||
dumpmem2("double",hdr,12);
|
||||
strcat(hdr,"\n");
|
||||
fprintf(stderr,"%s",hdr);
|
||||
#endif
|
||||
|
||||
count = (len / sizeof(int));
|
||||
rem = (len % sizeof(int));
|
||||
@ -316,9 +326,9 @@ ocdumppacket(char* memory, int len, int bod)
|
||||
}
|
||||
|
||||
void
|
||||
ocdumpmemory(char* memory, int len)
|
||||
ocdumpmemory(char* memory, int len, int bod)
|
||||
{
|
||||
dumpmemory0(memory,len,0,0);
|
||||
dumpmemory0(memory,len,0,bod);
|
||||
}
|
||||
|
||||
void
|
||||
@ -479,7 +489,9 @@ ocdd(OCstate* state, OCnode* root)
|
||||
#ifdef OC_DISK_STORAGE
|
||||
ocdumpfile(root->tree->data.file,root->tree->data.bod);
|
||||
#else
|
||||
ocdumpmemory(root->tree->data.xdrdata,root->tree->data.bod);
|
||||
ocdumpmemory(root->tree->data.xdrdata,
|
||||
root->tree->data.datasize,
|
||||
root->tree->data.bod);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ extern void ocdumpnode(OCnode* node);
|
||||
extern void ocdumpslice(OCslice* slice);
|
||||
extern void ocdumpclause(OCprojectionclause* ref);
|
||||
|
||||
extern void ocdumpmemory(char* memory, int len);
|
||||
extern void ocdumpmemory(char* memory, int len, int bod);
|
||||
extern void ocdumppacket(char* memory, int len, int bod);
|
||||
|
||||
extern void ocdumpfile(FILE* file, int datastart);
|
||||
|
@ -60,7 +60,7 @@ mktemp(tmpl); ret=open(tmpl,O_RDWR|O_BINARY|O_CREAT|O_EXCL|_O_SHORT_LIVED, _S_IR
|
||||
#endif
|
||||
|
||||
/* Global flags*/
|
||||
static int oc_big_endian;
|
||||
static int oc_big_endian; /* what is this machine? */
|
||||
int oc_network_order; /* network order is big endian */
|
||||
int oc_invert_xdr_double;
|
||||
int oc_curl_file_supported;
|
||||
@ -72,6 +72,7 @@ ocinternalinitialize(void)
|
||||
int stat = OC_NOERR;
|
||||
|
||||
/* Compute if we are same as network order v-a-v xdr */
|
||||
|
||||
#ifdef XDRBYTEORDER
|
||||
{
|
||||
XDR xdrs;
|
||||
@ -90,8 +91,9 @@ ocinternalinitialize(void)
|
||||
int testint = 0x00000001;
|
||||
char *byte = (char *)&testint;
|
||||
oc_big_endian = (byte[0] == 0 ? 1 : 0);
|
||||
oc_network_order = oc_big_endian;
|
||||
oc_network_order = oc_big_endian;
|
||||
}
|
||||
|
||||
#endif /*XDRBYTEORDER*/
|
||||
{
|
||||
/* It turns out that various machines
|
||||
@ -416,7 +418,7 @@ ocextractdds(OCstate* state, OCtree* tree)
|
||||
ocbytesclear(state->packet);
|
||||
rewind(tree->data.file);
|
||||
do {
|
||||
char chunk[128];
|
||||
char chunk[1024];
|
||||
size_t count;
|
||||
/* read chunks of the file until we find the separator*/
|
||||
count = fread(chunk,1,sizeof(chunk),tree->data.file);
|
||||
|
@ -231,7 +231,7 @@ extern OCerror ocupdatelastmodifieddata(OCstate* state);
|
||||
|
||||
extern int ocinternalinitialize(void);
|
||||
|
||||
/* Use my own ntohl an htonl */
|
||||
/* Use my own ntohl and htonl */
|
||||
#define ocntoh(i) (oc_network_order?(i):ocbyteswap((i)))
|
||||
#define ochton(i) ocntoh(i)
|
||||
|
||||
|
30
oc/ocutil.c
30
oc/ocutil.c
@ -10,8 +10,8 @@
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
static char* DDSdatamark = "Data:";
|
||||
static char* DDSdatamarkR = "Data:\r";
|
||||
/* Order is important: longest first */
|
||||
static char* DDSdatamarks[3] = {"Data:\r\n","Data:\n",(char*)NULL};
|
||||
|
||||
/* Not all systems have strndup, so provide one*/
|
||||
char*
|
||||
@ -100,19 +100,21 @@ findbod(OCbytes* buffer, size_t* bodp, size_t* ddslenp)
|
||||
unsigned int i;
|
||||
char* content;
|
||||
size_t len = ocbyteslength(buffer);
|
||||
int tlen = strlen(DDSdatamark);
|
||||
|
||||
char** marks;
|
||||
|
||||
content = ocbytescontents(buffer);
|
||||
for(i=0;i<len;i++) {
|
||||
if((i+tlen) <= len
|
||||
&& (strncmp(content+i,DDSdatamark,tlen)==0
|
||||
|| strncmp(content+i,DDSdatamarkR,tlen)==0)) {
|
||||
*ddslenp = i;
|
||||
i += tlen;
|
||||
if(i < len && content[i] == '\r') i++;
|
||||
if(i < len && content[i] == '\n') i++;
|
||||
*bodp = i;
|
||||
return 1;
|
||||
|
||||
for(marks = DDSdatamarks;*marks;marks++) {
|
||||
char* mark = *marks;
|
||||
int tlen = strlen(mark);
|
||||
for(i=0;i<len;i++) {
|
||||
if((i+tlen) <= len
|
||||
&& (strncmp(content+i,mark,tlen)==0)) {
|
||||
*ddslenp = i;
|
||||
i += tlen;
|
||||
*bodp = i;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*ddslenp = 0;
|
||||
|
@ -152,8 +152,11 @@ ocxdrstdio_getlong(xdrs, lp)
|
||||
XDR *xdrs;
|
||||
register unsigned int *lp;
|
||||
{
|
||||
#ifdef IGNORE
|
||||
FILE* f = (FILE*)xdrs->x_private;
|
||||
ftell(f);
|
||||
long fpos = ftell(f);
|
||||
#endif
|
||||
|
||||
if(fread((caddr_t)lp,sizeof(unsigned int),1,(FILE *)(xdrs->x_private)) != 1)
|
||||
return (FALSE);
|
||||
#ifndef mc68000
|
||||
|
Loading…
Reference in New Issue
Block a user