mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-19 17:30:27 +08:00
fix dfile.c error reporting
This commit is contained in:
parent
85382f21bc
commit
c114861e68
@ -125,7 +125,7 @@ NC_check_file_type(const char *path, int use_parallel, void *mpi_info,
|
||||
i = fread(magic, MAGIC_NUMBER_LEN, 1, fp);
|
||||
fclose(fp);
|
||||
if(i != 1)
|
||||
return errno;
|
||||
return NC_ENOTNC;
|
||||
}
|
||||
|
||||
/* Ignore the first byte for HDF */
|
||||
@ -140,7 +140,10 @@ NC_check_file_type(const char *path, int use_parallel, void *mpi_info,
|
||||
*cdf = 1; /* netcdf classic version 1 */
|
||||
else if(magic[3] == '\002')
|
||||
*cdf = 2; /* netcdf classic version 2 */
|
||||
}
|
||||
else
|
||||
return NC_ENOTNC;
|
||||
} else
|
||||
return NC_ENOTNC;
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
@ -1567,8 +1570,8 @@ NC_open(const char *path, int cmode,
|
||||
} else if(cdfversion != 0) {
|
||||
model = NC_DISPATCH_NC3;
|
||||
}
|
||||
}
|
||||
/* else ignore the file */
|
||||
} else /* presumably not a netcdf file */
|
||||
return NC_ENOTNC;
|
||||
}
|
||||
|
||||
/* Look to the incoming cmode for hints */
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "ocinternal.h"
|
||||
#include "ocdebug.h"
|
||||
|
||||
|
||||
/* For consistency with Java parser */
|
||||
#define null NULL
|
||||
|
||||
|
@ -343,23 +343,24 @@ createtempfile1(char* tmppath, char** tmpnamep)
|
||||
{
|
||||
int fd = 0;
|
||||
char* tmpname = NULL;
|
||||
tmpname = (char*)malloc(strlen(tmppath)+strlen("dataddsXXXXXX")+1);
|
||||
int tmpsize = strlen(tmppath)+strlen("dataddsXXXXXX");
|
||||
tmpname = (char*)malloc(tmpsize+1);
|
||||
if(tmpname == NULL) return -1;
|
||||
strcpy(tmpname,tmppath);
|
||||
strncpy(tmpname,tmppath,tmpsize);
|
||||
#ifdef HAVE_MKSTEMP
|
||||
strcat(tmpname,"dataddsXXXXXX");
|
||||
strncat(tmpname,"dataddsXXXXXX",strlen("dataddsXXXXXX")));
|
||||
/* Note Potential problem: old versions of this function
|
||||
leave the file in mode 0666 instead of 0600 */
|
||||
fd = mkstemp(tmpname);
|
||||
#else /* !HAVE_MKSTEMP */
|
||||
/* Need to simulate by using some kind of pseudo-random number */
|
||||
strcat(tmpname,"datadds");
|
||||
strncat(tmpname,"datadds",strlen("datadds"));
|
||||
{
|
||||
int rno = rand();
|
||||
char spid[7];
|
||||
if(rno < 0) rno = -rno;
|
||||
sprintf(spid,"%06d",rno);
|
||||
strcat(tmpname,spid);
|
||||
snprintf(spid,sizeof(spid),"%06d",rno);
|
||||
strncat(tmpname,spid,strlen(spid));
|
||||
# ifdef WIN32
|
||||
fd=open(tmpname,O_RDWR|O_BINARY|O_CREAT|O_EXCL|FILE_ATTRIBUTE_TEMPORARY, _S_IREAD|_S_IWRITE);
|
||||
# else
|
||||
@ -371,7 +372,6 @@ createtempfile1(char* tmppath, char** tmpnamep)
|
||||
if(tmpnamep) *tmpnamep = tmpname;
|
||||
else
|
||||
free(tmpname);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
@ -557,8 +557,8 @@ ocsetcurlproperties(OCstate* state)
|
||||
}
|
||||
}
|
||||
if(state->curlflags.useragent == NULL) {
|
||||
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
|
||||
char* agent = (char*)malloc(len);
|
||||
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION);
|
||||
char* agent = (char*)malloc(len+1);
|
||||
snprintf(agent,len,"%s%s",DFALTUSERAGENT,VERSION);
|
||||
state->curlflags.useragent = agent;
|
||||
}
|
||||
|
@ -13,10 +13,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#ifndef WIN32
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
44
oc2/ocutil.c
44
oc2/ocutil.c
@ -551,3 +551,47 @@ ocdtmodestring(OCDT mode,int compact)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Instead of using snprintf to concatenate
|
||||
multiple strings into a given target,
|
||||
provide a direct concatenator.
|
||||
So, this function concatenates n strings
|
||||
into dst, being careful to not overrun size.
|
||||
Note that size is assumed to include the null
|
||||
terminator and that in the event of overrun,
|
||||
the string will have a null at dst[size-1].
|
||||
Return -1 if overrun, 0 otherwise.
|
||||
*/
|
||||
int
|
||||
occoncat(char* dst, size_t size, size_t n, ...)
|
||||
{
|
||||
va_list args;
|
||||
size_t avail = size - 1;
|
||||
int i;
|
||||
int status = 0; // assume ok
|
||||
char* p = dst;
|
||||
|
||||
if(n == 0) {
|
||||
if(size > 0)
|
||||
dst[0] = '\0';
|
||||
return (size > 0 ? 0: -1);
|
||||
}
|
||||
|
||||
va_start(args,n);
|
||||
for(i=0;i<n;i++) {
|
||||
char* q = va_arg(args, char*);
|
||||
for(;;) {
|
||||
int c = *q++;
|
||||
if(c == '\0') break;
|
||||
if(avail == 0) {status = -1; goto done;}
|
||||
*p++ = c;
|
||||
avail--;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
va_end(args);
|
||||
return status;
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ extern void ocdataddsmsg(struct OCstate*, struct OCtree*);
|
||||
|
||||
extern const char* ocdtmodestring(OCDT mode,int compact);
|
||||
|
||||
extern int occoncat(char* dst, size_t size, size_t n, ...);
|
||||
|
||||
/* Define some classifiers */
|
||||
#define iscontainer(t) ((t) == OC_Dataset || (t) == OC_Structure || (t) == OC_Sequence || (t) == OC_Grid)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user