From 2bc8658e85e2cb29daa1be362a42b8234aff7c74 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 23 Feb 2018 14:47:00 +0000 Subject: libgcompat: add internal api for GCOMPAT__panic(). --- Makefile | 2 ++ libgcompat/internal.c | 17 +++++++++++++++++ libgcompat/internal.h | 14 ++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 libgcompat/internal.c create mode 100644 libgcompat/internal.h diff --git a/Makefile b/Makefile index b6bee29..0b4e76c 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ LIBGCOMPAT_SRC = \ libgcompat/execinfo.c \ libgcompat/gnulib.c \ libgcompat/grp.c \ + libgcompat/internal.c \ libgcompat/malloc.c \ libgcompat/math.c \ libgcompat/misc.c \ @@ -53,6 +54,7 @@ ${LOADER_NAME}: ${LOADER_OBJ} .c.o: $(CC) -c -D_BSD_SOURCE -DLIBGCOMPAT=\"${LIBGCOMPAT_PATH}\" \ -DLINKER=\"${LINKER_PATH}\" -DLOADER=\"${LOADER_NAME}\" \ + -Ilibgcompat \ -fPIC -std=c99 -Wall -Wextra -Wno-frame-address \ -Wno-unused-parameter ${CFLAGS} ${CPPFLAGS} -o $@ $< diff --git a/libgcompat/internal.c b/libgcompat/internal.c new file mode 100644 index 0000000..441b3cc --- /dev/null +++ b/libgcompat/internal.c @@ -0,0 +1,17 @@ +#include +#include +#include + + +void GCOMPAT__panic(const char *fmt, ...) +{ + va_list va; + + fprintf(stderr, "*** gcompat panic ***\n"); + + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); + + abort(); +} diff --git a/libgcompat/internal.h b/libgcompat/internal.h new file mode 100644 index 0000000..bb107bc --- /dev/null +++ b/libgcompat/internal.h @@ -0,0 +1,14 @@ +#ifndef LIBGCOMPAT_INTERNAL_H +#define LIBGCOMPAT_INTERNAL_H + +void GCOMPAT__panic(const char *fmt, ...) __attribute__((noreturn)); + +#define GCOMPAT__assert_with_reason(chk, fmt, ...) \ + do { \ + if (!(chk)) { \ + GCOMPAT__panic(fmt, __VA_ARGS__); \ + } \ + } \ + while(0); + +#endif -- cgit v1.2.3-60-g2f50