1
0
forked from GitHub/gf-core

initial import of the C runtime

This commit is contained in:
kr.angelov
2012-01-20 13:41:10 +00:00
parent 2fd04e0797
commit a369d3bdac
94 changed files with 14344 additions and 1277 deletions

53
src/runtime/c/gu/assert.c Normal file
View File

@@ -0,0 +1,53 @@
#include <gu/assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
const char*
gu_assert_mode_descs[] = {
[GU_ASSERT_PRECOND] = "precondition failed",
[GU_ASSERT_POSTCOND] = "postcondition failed",
[GU_ASSERT_ASSERTION] = "assertion failed",
[GU_ASSERT_NEVER] = "control should not reach here",
};
void
gu_abort_v_(GuAssertMode mode,
const char* file, const char* func, int line,
const char* msg_fmt, va_list args)
{
const char* desc = gu_assert_mode_descs[mode];
(void) fprintf(stderr, "%s (%s:%d): %s\n", func, file, line, desc);
if (msg_fmt != NULL) {
(void) fputc('\t', stderr);
(void) vfprintf(stderr, msg_fmt, args);
(void) fputc('\n', stderr);
}
abort();
}
void
gu_abort_(GuAssertMode mode,
const char* file, const char* func, int line,
const char* msg_fmt, ...)
{
va_list args;
va_start(args, msg_fmt);
gu_abort_v_(mode, file, func, line, msg_fmt, args);
va_end(args);
}
void
gu_fatal(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
fputs("Fatal error", stderr);
if (fmt) {
fputs(": ", stderr);
(void) vfprintf(stderr, fmt, args);
}
fputc('\n', stderr);
abort();
}