aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/error/error.c20
-rw-r--r--src/error/module.mk1
3 files changed, 22 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index fa64d3a..794fe6b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,7 @@ CC=gcc-6
OUTPUT_OPTION=-MMD -MP -o $@
CFLAGS += -Wall -Ofast --std=c99 -Wvla -I../include
-MODULES := options file
+MODULES := options file error
CFLAGS += $(patsubst %,-I%,$(MODULES))
LIBS :=
diff --git a/src/error/error.c b/src/error/error.c
new file mode 100644
index 0000000..c286b46
--- /dev/null
+++ b/src/error/error.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include "error.h"
+
+void error(int err, char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ fprintf(stderr, "error: ");
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+ if (err != 0)
+ fprintf(stderr, "%s", strerror(err));
+ exit(1);
+}
diff --git a/src/error/module.mk b/src/error/module.mk
new file mode 100644
index 0000000..28eabc5
--- /dev/null
+++ b/src/error/module.mk
@@ -0,0 +1 @@
+SRC += error/error.c