17 #define MAX(a,b) ((a)>(b)?(a):(b))
23 static FILE *agerrout;
50 endpos = ftell(agerrout);
51 len = endpos - aglast;
52 buf = (
char*)malloc(len + 1);
53 fseek(agerrout, aglast, SEEK_SET);
54 fread(buf,
sizeof(
char), len, agerrout);
56 fseek(agerrout, endpos, SEEK_SET);
65 userout (
agerrlevel_t level,
const char *fmt, va_list args)
68 static int bufsz = 1024;
73 buf = (
char*)malloc(bufsz);
75 fputs(
"userout: could not allocate memory\n", stderr );
81 usererrf ((level ==
AGERR) ?
"Error" :
"Warning");
86 n = vsnprintf(buf, bufsz, fmt, args);
87 if ((n > -1) && (n < bufsz)) {
91 bufsz =
MAX(bufsz*2,n+1);
92 if ((np = (
char*)realloc(buf, bufsz)) ==
NULL) {
93 fputs(
"userout: could not allocate memory\n", stderr );
100 static int agerr_va(
agerrlevel_t level,
const char *fmt, va_list args)
112 agmaxerr =
MAX(agmaxerr, agerrno);
117 if (lvl >= agerrlevel) {
119 userout (level, fmt, args);
122 fprintf(stderr,
"%s: ", (level ==
AGERR) ?
"Error" :
"Warning");
123 vfprintf(stderr, fmt, args);
130 agerrout = tmpfile();
136 aglast = ftell(agerrout);
137 vfprintf(agerrout, fmt, args);
147 ret = agerr_va(level, fmt, args);
157 agerr_va(
AGERR, fmt, args);
166 agerr_va(
AGWARN, fmt, args);
agerrlevel_t agseterr(agerrlevel_t lvl)
int agerr(agerrlevel_t level, const char *fmt,...)
int(* agusererrf)(char *)
agusererrf agseterrf(agusererrf newf)
void agwarningf(const char *fmt,...)
void agerrorf(const char *fmt,...)