1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/*
* Copyright 1993, University Corporation for Atmospheric Research
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*/
/* $Id: error.c,v 1.14 90/02/23 16:08:55 davis Exp */
/*
* Utility Functions to implement consistant error logging
* mechanisms for netcdf
*/
/*LINTLIBRARY*/
#ifdef NO_STDARG /* The 4.0 release should be ANSI compliant */
#undef NO_STDARG
#endif
#include "local_nc.h"
#include <stdio.h>
#ifndef NO_STDARG
#include <stdarg.h>
#else
/* try varargs instead */
#include <varargs.h>
#endif /* !NO_STDARG */
#include <errno.h>
#if defined ERRNO_MISSING
extern int errno;
#endif
#ifdef VMS
#include <ssdef.h>
#endif
#ifndef NO_STRERROR
#include <string.h> /* contains prototype for ansi libc function strerror() */
#else
/* provide a strerror function for older unix systems */
char *
strerror(errnum)
int errnum ;
{
extern int sys_nerr;
extern const char * const sys_errlist[];
if (errnum < 0 || errnum >= sys_nerr)
return NULL ;
return (char *)sys_errlist[errnum] ;
}
#endif /* NO_STRERROR */
#ifdef vms
/*
* On the vms system, when a system error occurs which is not
* mapped into the unix styled errno values, errno is set EVMSERR
* and a VMS error code is set in vaxc$errno.
* This routine prints the systems message associated with status return
* from a system services call.
*/
#include <descrip.h>
#include <ssdef.h>
static int
vmserror1( int status )
{
short msglen ;
char msgbuf[256] ;
$DESCRIPTOR(message, msgbuf) ;
register ret ;
ret = SYS$GETMSG(status, &msglen, &message, 15, 0) ;
switch(ret) {
case SS$_BUFFEROVF :
case SS$_NORMAL :
(void) fprintf(stderr, "%.*s\n", msglen, msgbuf) ;
break ;
default :
break ;
}
return(ret) ;
}
#endif /* vms */
#ifdef USE_doprnt_FOR_vfprintf
/*
* kludge for ze ancienne regieme
*/
vfprintf(stream, fmt, va_alist)
FILE *stream;
char *fmt;
va_dcl
{
return _doprnt(fmt, va_alist, stream);
}
#endif
/*
* Log SYSTEM errors
* Use where you would want to call perror(3).
* Calling sequence is
* nc_serror(format, arg1, arg2,...)
* with zero or more args of types compatible with the associated format
* specifiers. For example:
* nc_serror("shutting down");
* nc_serror("can't open %s", file_name);
* nc_serror("process %d in state %s",pid,state);
*/
void
#ifndef NO_STDARG
nc_serror(const char *fmt, ...)
#else
/*VARARGS1*/
nc_serror(fmt, va_alist)
const char *fmt ;
va_dcl
#endif /* !NO_STDARG */
{
if( ncopts & NC_VERBOSE ) {
va_list args ;
static const char unknown[] = "Unknown Error";
int errnum = errno; /* save real errno in case we wipe it out */
const char * cp;
#ifndef NO_STDARG
va_start(args, fmt) ;
#else
va_start(args) ;
#endif /* !NO_STDARG */
(void) fprintf(stderr,"%s: ", cdf_routine_name);
(void) vfprintf(stderr,fmt,args) ;
va_end(args) ;
switch(errnum) {
case 0 :
ncerr = NC_NOERR ;
(void) fputc('\n',stderr) ;
break ;
#ifdef vms
case EVMSERR :
ncerr = NC_SYSERR ;
(void) fputc(': ',stderr) ;
(void) vmserror1(vaxc$errno) ;
break ;
#endif /* vms */
default :
ncerr = NC_SYSERR ;
(void) fprintf(stderr,": %s\n",
(cp = strerror(errnum)) == NULL ? unknown : cp ) ;
break ;
}
(void) fflush(stderr); /* to ensure log files are current */
errno = 0 ; /* ??? */
} /* NC_VERBOSE */
if( ncopts & NC_FATAL ) {
exit(ncopts) ;
}
}
/*
* Like nc_serror above, but doesn't check for system error.
* Use for logging error conditions which are not system errors.
* Calling sequence is
* NCadvise(ncerr, format, arg1, arg2,...)
* with zero or more args of types compatible with the associated format
* specifiers. For example:
* NCadvise(NC_NOERR, "just advice");
* NCadvise(NC_EBADID, "%d is not a valid cdf id", cdfid);
*/
#ifndef NO_STDARG
void
NCadvise(int err, const char *fmt,...)
#else
/*VARARGS1*/
void
NCadvise(err, fmt, va_alist)
int err ;
const char *fmt ;
va_dcl
#endif /* !NO_STDARG */
{
va_list args ;
ncerr = err ;
if( ncopts & NC_VERBOSE )
{
(void) fprintf(stderr,"%s: ", cdf_routine_name);
#ifndef NO_STDARG
va_start(args ,fmt) ;
#else
va_start(args) ;
#endif /* !NO_STDARG */
(void) vfprintf(stderr,fmt,args) ;
va_end(args) ;
(void) fputc('\n',stderr) ;
(void) fflush(stderr); /* to ensure log files are current */
}
if( (ncopts & NC_FATAL) && ncerr != NC_NOERR )
{
exit(ncopts) ;
}
}
|