summaryrefslogtreecommitdiff
path: root/base/base_error.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-06-04 15:58:45 +0200
committerTor Andersson <tor@ghostscript.com>2005-06-04 15:58:45 +0200
commit7ee19483ed81a885f464d4e93f4eefb3d4037d30 (patch)
treee4d3faf561e694ae0cc7873381450db6a011ab5a /base/base_error.c
parentaf699a4657e103bd8fa72356eb3abebf221fe93a (diff)
downloadmupdf-7ee19483ed81a885f464d4e93f4eefb3d4037d30.tar.xz
new world order
Diffstat (limited to 'base/base_error.c')
-rw-r--r--base/base_error.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/base/base_error.c b/base/base_error.c
new file mode 100644
index 00000000..926c48dc
--- /dev/null
+++ b/base/base_error.c
@@ -0,0 +1,78 @@
+#include <fitz.h>
+
+void
+fz_warn(char *fmt, ...)
+{
+ va_list ap;
+ fprintf(stderr, "warning: ");
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+}
+
+fz_error *
+fz_throw1(char *fmt, ...)
+{
+ va_list ap;
+ fz_error *eo;
+
+ eo = fz_malloc(sizeof(fz_error));
+ if (!eo) return fz_outofmem;
+
+ eo->refs = 1;
+ strlcpy(eo->func, "unknown", sizeof eo->func);
+ strlcpy(eo->file, "unknown", sizeof eo->file);
+ eo->line = 0;
+
+ va_start(ap, fmt);
+ vsnprintf(eo->msg, sizeof eo->msg, fmt, ap);
+ eo->msg[sizeof(eo->msg) - 1] = '\0';
+ va_end(ap);
+
+ return eo;
+}
+
+fz_error *
+fz_throw0(const char *func, const char *file, int line, char *fmt, ...)
+{
+ va_list ap;
+ fz_error *eo;
+
+ eo = fz_malloc(sizeof(fz_error));
+ if (!eo) return fz_outofmem;
+
+ eo->refs = 1;
+ strlcpy(eo->func, func, sizeof eo->func);
+ strlcpy(eo->file, file, sizeof eo->file);
+ eo->line = line;
+
+ va_start(ap, fmt);
+ vsnprintf(eo->msg, sizeof eo->msg, fmt, ap);
+ eo->msg[sizeof(eo->msg) - 1] = '\0';
+ va_end(ap);
+
+ if (getenv("BOMB"))
+ fz_abort(eo);
+
+ return eo;
+}
+
+void
+fz_droperror(fz_error *eo)
+{
+ if (eo->refs > 0)
+ eo->refs--;
+ if (eo->refs == 0)
+ fz_free(eo);
+}
+
+void
+fz_abort(fz_error *eo)
+{
+ fflush(stdout);
+ fprintf(stderr, "%s:%d: %s(): %s\n", eo->file, eo->line, eo->func, eo->msg);
+ fflush(stderr);
+ abort();
+}
+