protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

error.c (632B)


      1 
      2 #include "error.h"
      3 
      4 #include <stdlib.h>
      5 #include <stdarg.h>
      6 
      7 int note_error_(struct errors *errs_, struct cursor *p, const char *fmt, ...)
      8 {
      9 	static char buf[512];
     10 	struct error err;
     11 	struct cursor *errs;
     12 	va_list ap;
     13 
     14 	errs = &errs_->cur;
     15 
     16 	if (errs_->enabled == 0)
     17 		return 0;
     18 
     19 	va_start(ap, fmt);
     20 	vsprintf(buf, fmt, ap);
     21 	va_end(ap);
     22 
     23 	err.msg = buf;
     24 	err.pos = p ? p->p - p->start : 0;
     25 
     26 	if (!cursor_push_error(errs, &err)) {
     27 		fprintf(stderr, "arena OOM when recording error, ");
     28 		fprintf(stderr, "errs->p at %ld, remaining %ld, strlen %ld\n",
     29 				errs->p - errs->start, errs->end - errs->p, strlen(buf));
     30 	}
     31 
     32 	return 0;
     33 }
     34