2012-08-01 04:34:13 +08:00
|
|
|
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
|
|
|
See the COPYRIGHT file for more information. */
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-12-19 05:08:23 +08:00
|
|
|
#ifdef HAVE_STDARG_H
|
2012-08-01 04:34:13 +08:00
|
|
|
#include <stdarg.h>
|
2012-12-19 05:08:23 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
#include "ocinternal.h"
|
|
|
|
#include "ocdebug.h"
|
|
|
|
|
|
|
|
int ocdebug;
|
|
|
|
|
|
|
|
#ifdef OCCATCHERROR
|
|
|
|
/* Place breakpoint here to catch errors close to where they occur*/
|
2014-05-09 04:13:51 +08:00
|
|
|
OCerror
|
|
|
|
ocbreakpoint(OCerror err) {return err;}
|
2012-08-01 04:34:13 +08:00
|
|
|
|
2014-05-09 04:13:51 +08:00
|
|
|
OCerror
|
2014-12-25 01:22:47 +08:00
|
|
|
occatch(OCerror err)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
if(err == 0) return err;
|
|
|
|
return ocbreakpoint(err);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
2013-03-25 01:33:17 +08:00
|
|
|
xxdrerror(void)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
2017-03-09 08:01:10 +08:00
|
|
|
nclog(NCLOGERR,"xdr failure");
|
2014-12-25 01:22:47 +08:00
|
|
|
return OCCATCH(OC_EDATADDS);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void*
|
|
|
|
occalloc(size_t size, size_t nelems)
|
|
|
|
{
|
|
|
|
return ocmalloc(size*nelems);
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
ocmalloc(size_t size)
|
|
|
|
{
|
|
|
|
void* memory = calloc(size,1); /* use calloc to zero memory*/
|
2017-03-09 08:01:10 +08:00
|
|
|
if(memory == NULL) nclog(NCLOGERR,"ocmalloc: out of memory");
|
2012-08-01 04:34:13 +08:00
|
|
|
return memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ocfree(void* mem)
|
|
|
|
{
|
|
|
|
if(mem != NULL) free(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ocpanic(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
if(fmt != NULL) {
|
|
|
|
va_start(args, fmt);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
fprintf(stderr, "\n" );
|
|
|
|
va_end( args );
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "panic" );
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n" );
|
|
|
|
fflush(stderr);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-25 01:22:47 +08:00
|
|
|
|
|
|
|
CURLcode
|
|
|
|
ocreportcurlerror(OCstate* state, CURLcode cstat)
|
|
|
|
{
|
|
|
|
if(cstat != CURLE_OK) {
|
|
|
|
fprintf(stderr,"CURL Error: %s",curl_easy_strerror(cstat));
|
|
|
|
if(state != NULL)
|
|
|
|
fprintf(stderr," ; %s",state->error.curlerrorbuf);
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|
|
|
|
fflush(stderr);
|
|
|
|
return cstat;
|
|
|
|
}
|