summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-31 00:00:51 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-31 00:00:51 -0500
commit36bd6c283383851664bbe598601c99385e5dcd43 (patch)
tree841682120f19b993eb6de1e6a0c30dda6a11aabf
parentf10737a4ee4a818acdc28fa2e32c85a74f47eb5c (diff)
make tweaks to work with 1:1 checked functions
-rw-r--r--mk/__checked_i.d9
-rw-r--r--mk/all.mk2
-rw-r--r--mk/deps.mk8
-rw-r--r--src/__checked_call.c4
-rw-r--r--src/__checked_i.c484
-rw-r--r--src/_safety.h53
-rw-r--r--src/setjmp/longjmp.c2
-rw-r--r--src/signal/__signal.c2
-rw-r--r--src/signal/__signal_handler.c8
-rw-r--r--src/signal/_signal.h2
-rw-r--r--src/signal/signal.c8
-rw-r--r--src/stdio/__printf.c2
-rw-r--r--src/stdlib/__stdlib.c4
-rw-r--r--src/stdlib/abort_handler_s.c4
14 files changed, 71 insertions, 521 deletions
diff --git a/mk/__checked_i.d b/mk/__checked_i.d
deleted file mode 100644
index 76b745be..00000000
--- a/mk/__checked_i.d
+++ /dev/null
@@ -1,9 +0,0 @@
-libc_C.0: libc.a(__checked_i.o)
-libc.a(__checked_i.o): $(OBJDIR)/__checked_i.o
- @$(AR) $(ARFLAGS) $@ $(OBJDIR)/$%
-
-$(OBJDIR)/__checked_i.o: src/__checked_i.c
-$(OBJDIR)/__checked_i.o: src/_safety.h
-$(OBJDIR)/__checked_i.o:
- @mkdir -p $(@D)
- $(CC) -c -o $@ $(CFLAGS) src/__checked_i.c
diff --git a/mk/all.mk b/mk/all.mk
index 7d5ff1d9..d8b4f9df 100644
--- a/mk/all.mk
+++ b/mk/all.mk
@@ -388,6 +388,7 @@ include mk/shmctl.d
include mk/shmdt.d
include mk/ftok.d
include mk/times.d
+include mk/struct_tms.d
include mk/waitpid.d
include mk/wait.d
include mk/waitid.d
@@ -673,7 +674,6 @@ include mk/fesetexceptflag.d
include mk/fegetround.d
include mk/fetestexcept.d
include mk/fegetexceptflag.d
-include mk/__checked_i.d
include mk/__sys.x86-64.s.d
include mk/__setjmp.x86-64.s.d
include mk/__longjmp.x86-64.s.d
diff --git a/mk/deps.mk b/mk/deps.mk
index 86dd74bc..a0040674 100644
--- a/mk/deps.mk
+++ b/mk/deps.mk
@@ -1562,6 +1562,10 @@ all: mk/times.d
mk/times.d: src/sys/times/times.c
sh mk/deps.sh src/sys/times/times.c
+all: mk/struct_tms.d
+mk/struct_tms.d: src/sys/times/struct_tms.c
+ sh mk/deps.sh src/sys/times/struct_tms.c
+
all: mk/waitpid.d
mk/waitpid.d: src/sys/wait/waitpid.c
sh mk/deps.sh src/sys/wait/waitpid.c
@@ -2710,10 +2714,6 @@ all: mk/fegetexceptflag.d
mk/fegetexceptflag.d: src/fenv/fegetexceptflag.c
sh mk/deps.sh src/fenv/fegetexceptflag.c
-all: mk/__checked_i.d
-mk/__checked_i.d: src/__checked_i.c
- sh mk/deps.sh src/__checked_i.c
-
all: mk/__sys.x86-64.s.d
mk/__sys.x86-64.s.d: src/__sys.x86-64.s
sh mk/deps.sh src/__sys.x86-64.s
diff --git a/src/__checked_call.c b/src/__checked_call.c
index f11c708a..eb07ffd4 100644
--- a/src/__checked_call.c
+++ b/src/__checked_call.c
@@ -4,3 +4,7 @@
_Thread_local
#endif
struct __checked_call __checked_call = { 0 };
+
+#ifdef abort_handler_s
+#include "stdlib/abort_handler_s.c"
+#endif
diff --git a/src/__checked_i.c b/src/__checked_i.c
deleted file mode 100644
index e7e92919..00000000
--- a/src/__checked_i.c
+++ /dev/null
@@ -1,484 +0,0 @@
-#undef __UNG_INTERNAL__
-
-#include <ctype.h>
-#include <locale.h>
-#include <math.h> /* TODO */
-#include <setjmp.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h> /* TODO */
-#include <string.h>
-#include <time.h> /* TODO */
-
-#if __STDC_VERSION__ >= 199409L
-#include <wchar.h> /* TODO */
-#include <wctype.h> /* TODO */
-#endif
-
-#if __STDC_VERSION__ >= 199901L
-#include <complex.h> /* TODO */
-#include <fenv.h>
-#include <inttypes.h>
-#endif
-
-#if __STDC_VERSION__ >= 201112
-#include <threads.h> /* TODO */
-#include <uchar.h> /* TODO */
-#endif
-
-#include "_safety.h"
-
-extern char *(gets)(char*);
-
-#define F(fn) (int(*)())(fn)
-
-int __checked_i(const char *file, const char *func, unsigned long long line, int (*fn)(), ...)
-{
- va_list ap;
- int ret = -1;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(isalpha)
- || fn == F(isdigit)
- || fn == F(isupper)
- || fn == F(islower)
- || fn == F(toupper)
- || fn == F(tolower)
- /*
- || fn == F(feclearexcept)
- || fn == F(feraiseexcept)
- || fn == F(fesetround)
- || fn == F(fetestexcept)
- */
- || fn == F(raise)
- || fn == F(putchar)
- || fn == F(abs)
- ) {
- int arg = va_arg(ap, int);
- ret = fn(arg);
- /*
- } else if (fn == F(fegetenv)
- || fn == F(feholdexcept)
- || fn == F(fesetenv)
- || fn == F(feupdateenv)
- ) {
- fenv_t *arg = va_arg(ap, fenv_t *);
- ret = fn(arg);
- } else if (fn == F(fegetexceptflag)
- || fn == F(fesetexceptflag)
- ) {
- fexcept_t *fe = va_arg(ap, fexcept_t *);
- int i = va_arg(ap, int);
- ret = fn(fe, i);
- */
- } else if (/*fn == F(fegetround)
- || */fn == F(getchar)
- ) {
- ret = fn();
- } else if (fn == F(fclose)
- || fn == F(feof)
- || fn == F(ferror)
- || fn == F(fflush)
- || fn == F(fgetc)
- /* || fn == F(getc) */
- ) {
- FILE *f = va_arg(ap, FILE *);
- ret = fn(f);
- } else if (fn == F(fgetpos)
- || fn == F(fsetpos)
- ) {
- FILE *f = va_arg(ap, FILE *);
- fpos_t *fp = va_arg(ap, fpos_t *);
- ret = fn(f, fp);
- } else if (fn == F(fputc)
- || fn == F(putc)
- || fn == F(ungetc)
- ) {
- int c = va_arg(ap, int);
- FILE *f = va_arg(ap, FILE *);
- ret = fn(c, f);
- } else if (fn == F(fputs)) {
- const char *s = va_arg(ap, const char *);
- FILE *f = va_arg(ap, FILE *);
- ret = fn(s, f);
- } else if (fn == F(fseek)) {
- FILE *f = va_arg(ap, FILE *);
- int o = va_arg(ap, int);
- int w = va_arg(ap, int);
- ret = fn(f, o, w);
- } else if (fn == F(puts)
- || fn == F(remove)
- ) {
- const char *s = va_arg(ap, const char *);
- ret = fn(s);
- } else if (fn == F(rename)
- || fn == F(strcmp)
- || fn == F(strcoll)
- ) {
- char *o = va_arg(ap, char *);
- char *n = va_arg(ap, char *);
- ret = fn(o, n);
- } else if (fn == F(setvbuf)) {
- FILE *f = va_arg(ap, FILE *);
- char *b = va_arg(ap, char *);
- int m = va_arg(ap, int);
- size_t s = va_arg(ap, size_t);
- ret = fn(f, b, m, s);
- } else if (fn == F(memcmp)) {
- const void *p1 = va_arg(ap, const void *);
- const void *p2 = va_arg(ap, const void *);
- size_t n = va_arg(ap, size_t);
- ret = fn(p1, p2, n);
- } else if (fn == F(strncmp)) {
- const char *p1 = va_arg(ap, const char *);
- const char *p2 = va_arg(ap, const char *);
- size_t n = va_arg(ap, size_t);
- ret = fn(p1, p2, n);
- /*
- } else if (fn == F(atexit)) {
- void *p = va_arg(ap, void *);
- ret = fn(p);
- */
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
-
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
-
-/*
-STDC(0)
-*/
-
-#if __STDC_VERSION__ >= 199901L
-#undef F
-#define F(fn) (intmax_t(*)())(fn)
-intmax_t __checked_im(const char *file, const char *func, unsigned long long line, intmax_t (*fn)(), ...)
-{
- va_list ap;
- intmax_t ret = -1;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(imaxabs)) {
- intmax_t i = va_arg(ap, intmax_t);
- ret = fn(i);
- } else if (fn == F(strtoimax)) {
- const char *s = va_arg(ap, const char *);
- char **end = va_arg(ap, char **);
- int i = va_arg(ap, int);
- ret = fn(s, end, i);
- } else if (fn == F(wcstoimax)) {
- const wchar_t *s = va_arg(ap, const wchar_t *);
- wchar_t **end = va_arg(ap, wchar_t **);
- int i = va_arg(ap, int);
- ret = fn(s, end, i);
- } else if (fn == F(strcspn)) {
- char *s1 = va_arg(ap, char *);
- char *s2 = va_arg(ap, char *);
- ret = fn(s1, s2);
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
-
-#undef F
-#define F(fn) (uintmax_t(*)())(fn)
-uintmax_t __checked_uim(const char *file, const char *func, unsigned long long line, uintmax_t (*fn)(), ...)
-{
- va_list ap;
- uintmax_t ret = 0;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(strtoumax)) {
- const char *s = va_arg(ap, const char *);
- char **end = va_arg(ap, char **);
- int i = va_arg(ap, int);
- ret = fn(s, end, i);
- } else if (fn == F(wcstoumax)) {
- const wchar_t *s = va_arg(ap, const wchar_t *);
- wchar_t **end = va_arg(ap, wchar_t **);
- int i = va_arg(ap, int);
- ret = fn(s, end, i);
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
-
-#undef F
-#define F(fn) (imaxdiv_t(*)())(fn)
-imaxdiv_t __checked_imd(const char *file, const char *func, unsigned long long line, imaxdiv_t (*fn)(), ...)
-{
- va_list ap;
- imaxdiv_t ret = {0};
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(imaxdiv)) {
- intmax_t n = va_arg(ap, intmax_t);
- intmax_t d = va_arg(ap, intmax_t);
- ret = fn(n, d);
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
-#endif
-
-#undef F
-#define F(fn) (void *(*)())(fn)
-void *__checked_p(const char *file, const char *func, unsigned long long line, void * (*fn)(), ...)
-{
- va_list ap;
- void *ret = NULL;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(localeconv)
- || fn == F(tmpfile)
- ) {
- ret = fn();
- } else if (fn == F(setlocale)) {
- int i = va_arg(ap, int);
- const char *s = va_arg(ap, const char *);
- ret = fn(i, s);
- } else if (fn == F(signal)) {
- int i = va_arg(ap, int);
- void *p = va_arg(ap, void *);
- ret = fn(i, p);
- } else if (fn == F(fgets)) {
- char *s = va_arg(ap, char *);
- int n = va_arg(ap, int);
- FILE *f = va_arg(ap, FILE *);
- ret = fn(s, n, f);
- } else if (fn == F(fopen)
- || fn == F(strcat)
- ) {
- char *s1 = va_arg(ap, char *);
- char *s2 = va_arg(ap, char *);
- ret = fn(s1, s2);
- } else if (fn == F(freopen)) {
- char *name = va_arg(ap, char *);
- char *mode = va_arg(ap, char *);
- FILE *f = va_arg(ap, FILE *);
- ret = fn(name, mode, f);
- } else if (fn == F(tmpnam)
- /* || fn == F(gets) */
- ) {
- char *s = va_arg(ap, char *);
- ret = fn(s);
- } else if (fn == F(memchr)
- || fn == F(memset)
- ) {
- void *p = va_arg(ap, void *);
- int c = va_arg(ap, int);
- size_t n = va_arg(ap, size_t);
- ret = fn(p, c, n);
- } else if (fn == F(memcpy)
- || fn == F(memmove)
- ) {
- void *p1 = va_arg(ap, void *);
- void *p2 = va_arg(ap, void *);
- size_t n = va_arg(ap, size_t);
- ret = fn(p1, p2, n);
- } else if (fn == F(strchr)
- || fn == F(strrchr)
- ) {
- char *s = va_arg(ap, char *);
- int c = va_arg(ap, int);
- ret = fn(s, c);
- } else if (fn == F(strerror)) {
- int n = va_arg(ap, int);
- ret = fn(n);
- } else if (fn == F(strncat)
- || fn == F(strncpy)
- || fn == F(strstr)
- || fn == F(strtok)
- ) {
- char *s1 = va_arg(ap, char *);
- char *s2 = va_arg(ap, char *);
- size_t n = va_arg(ap, size_t);
- ret = fn(s1, s2, n);
- } else if (fn == F(strcpy)
- || fn == F(strpbrk)
- ) {
- char *s1 = va_arg(ap, char *);
- char *s2 = va_arg(ap, char *);
- ret = fn(s1, s2);
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
-
-#undef F
-#define F(fn) (void(*)())(fn)
-void __checked(const char *file, const char *func, unsigned long long line, void(*fn)(), ...)
-{
- va_list ap;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(clearerr)
- || fn == F(rewind)
- ) {
- FILE *f = va_arg(ap, FILE *);
- fn(f);
- } else if (fn == F(perror)) {
- const char *s = va_arg(ap, const char *);
- fn(s);
- } else if (fn == F(setbuf)) {
- FILE *f = va_arg(ap, FILE *);
- char *b = va_arg(ap, char *);
- fn(f, b);
- } else if (fn == F(abort)) {
- fn();
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-}
-
-#undef F
-#define F(fn) (size_t(*)())(fn)
-size_t __checked_s(const char *file, const char *func, unsigned long long line, size_t (*fn)(), ...)
-{
- va_list ap;
- size_t ret = 0;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(fread)
- || fn == F(fwrite)
- ) {
- void *p = va_arg(ap, void *);
- size_t s = va_arg(ap, size_t);
- size_t n = va_arg(ap, size_t);
- FILE *f = va_arg(ap, FILE *);
- ret = fn(p, s, n, f);
- } else if (fn == F(strlen)) {
- char *s = va_arg(ap, char *);
- ret = fn(s);
- } else if (fn == F(strspn)) {
- const char *s1 = va_arg(ap, const char *);
- const char *s2 = va_arg(ap, const char *);
- ret = fn(s1, s2);
- } else if (fn == F(strxfrm)) {
- const char *s1 = va_arg(ap, const char *);
- const char *s2 = va_arg(ap, const char *);
- size_t n = va_arg(ap, size_t);
- ret = fn(s1, s2, n);
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
-
-#undef F
-#define F(fn) (long(*)())(fn)
-long __checked_l(const char *file, const char *func, unsigned long long line, long (*fn)(), ...)
-{
- va_list ap;
- long ret = 0;
-
- __checked_call.func = (char*)func;
- __checked_call.file = (char*)file;
- __checked_call.line = line;
-
- va_start(ap, fn);
-
- if (fn == F(ftell)) {
- FILE *f = va_arg(ap, FILE *);
- ret = fn(f);
- } else {
- (fprintf)(stderr, "Unwrapped function %s\n", func);
- (abort());
- }
-
- va_end(ap);
- __checked_call.func = NULL;
- __checked_call.file = NULL;
- __checked_call.line = 0;
-
- return ret;
-}
diff --git a/src/_safety.h b/src/_safety.h
index 76129899..1e11187a 100644
--- a/src/_safety.h
+++ b/src/_safety.h
@@ -1,6 +1,10 @@
#ifndef ___ASSERT_H__
#define ___ASSERT_H__
+#if ! (__STDC_VERSION__ >= 201112 && defined __STDC_WANT_LIB_EXT1__)
+#define abort_handler_s __abort_handler_s
+#endif
+
#include <errno.h>
#include <stdio.h>
#include "stdlib/_stdlib.h"
@@ -50,11 +54,11 @@ extern struct __checked_call {
} while (0)
#define SIGNAL_SAFE(__n) do { \
- if (__n == 0 && __signal.current != 0) { \
+ if (__n == 0 && ___signal.current != 0) { \
struct __constraint_info _ci = {0}; \
_ci.func = __func__; \
- _ci.signal = __signal.current; \
- __signal.current = 0; \
+ _ci.signal = ___signal.current; \
+ ___signal.current = 0; \
__stdlib.constraint_handler("Undefined behavior: " \
"Standard library function called from signal handler", \
&_ci, 0); \
@@ -68,14 +72,31 @@ extern struct __checked_call {
__checked_call.line = line; \
} while (0)
-#define __vcheck_0(__fn) \
- void __#__fn(const char * file, const char * func, unsigned long long line) { \
+#define VCHECK_0(__fn) \
+ void __##__fn(const char * file, const char * func, unsigned long long line) { \
__setchecked(file, func, line); \
__fn(); \
__setchecked(NULL, NULL, 0); \
}
+#define __vcheck_0(__fn) VCHECK_0(__fn)
+
+#define VCHECK_1(__fn, __t1) \
+ void __##__fn(const char * file, const char * func, unsigned long long line, __t1 __a1) { \
+ __setchecked(file, func, line); \
+ __fn(__a1); \
+ __setchecked(NULL, NULL, 0); \
+ }
+#define __vcheck_1(__fn, __t1) VCHECK_1(__fn, __t1)
+
+#define VCHECK_2(__fn, __t1, __t2) \
+ void __##__fn(const char * file, const char * func, unsigned long long line, __t1 __a1, __t2 __a2) { \
+ __setchecked(file, func, line); \
+ __fn(__a1, __a2); \
+ __setchecked(NULL, NULL, 0); \
+ }
+#define vcheck_2(__fn, __t1, __t2) VCHECK_2(__fn, __t1, __t2)
-#define __check_0(__type, __def, __fn) \
+#define CHECK_0(__type, __def, __fn) \
__type __##__fn(const char * file, const char * func, unsigned long long line) { \
__type ret = __def; \
__setchecked(file, func, line); \
@@ -83,8 +104,9 @@ extern struct __checked_call {
__setchecked(NULL, NULL, 0); \
return ret; \
}
+#define __check_0(__type, __def, __fn) CHECK_0(__type, __def, __fn)
-#define __check_1(__type, __def, __fn, __t1) \
+#define CHECK_1(__type, __def, __fn, __t1) \
__type __##__fn(const char * file, const char * func, unsigned long long line, __t1 a1) { \
__type ret = __def; \
__setchecked(file, func, line); \
@@ -92,8 +114,9 @@ extern struct __checked_call {
__setchecked(NULL, NULL, 0); \
return ret; \
}
+#define __check_1(__type, __def, __fn, __t1) CHECK_1(__type, __def, __fn, __t1)
-#define __check_2(__type, __def, __fn, __t1, __t2) \
+#define CHECK_2(__type, __def, __fn, __t1, __t2) \
__type __##__fn(const char * file, const char * func, unsigned long long line, __t1 a1, __t2 a2) { \
__type ret = __def; \
__setchecked(file, func, line); \
@@ -101,8 +124,9 @@ extern struct __checked_call {
__setchecked(NULL, NULL, 0); \
return ret; \
}
+#define __check_2(__type, __def, __fn, __t1, __t2) CHECK_2(__type, __def, __fn, __t1, __t2)
-#define __check_3(__type, __def, __fn, __t1, __t2, __t3) \
+#define CHECK_3(__type, __def, __fn, __t1, __t2, __t3) \
__type __##__fn(const char * file, const char * func, unsigned long long line, __t1 a1, __t2 a2, __t3 a3) { \
__type ret = __def; \
__setchecked(file, func, line); \
@@ -110,6 +134,17 @@ extern struct __checked_call {
__setchecked(NULL, NULL, 0); \
return ret; \
}
+#define __check_3(__type, __def, __fn, __t1, __t2, __t3) CHECK_3(__type, __def, __fn, __t1, __t2, __t3)
+
+#define CHECK_4(__type, __def, __fn, __t1, __t2, __t3, __t4) \
+ __type __##__fn(const char * file, const char * func, unsigned long long line, __t1 a1, __t2 a2, __t3 a3, __t4 a4) { \
+ __type ret = __def; \
+ __setchecked(file, func, line); \
+ ret = __fn(a1, a2, a3, a4); \
+ __setchecked(NULL, NULL, 0); \
+ return ret; \
+ }
+#define __check_4(__type, __def, __fn, __t1, __t2, __t3, __t4) CHECK_4(__type, __def, __fn, __t1, __t2, __t3, __t4)
#else
#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel)
diff --git a/src/setjmp/longjmp.c b/src/setjmp/longjmp.c
index c9ea0d28..117910fc 100644
--- a/src/setjmp/longjmp.c
+++ b/src/setjmp/longjmp.c
@@ -16,7 +16,7 @@ _Noreturn void longjmp(jmp_buf env, int val)
}
}
-__vcheck_2(longjmp, jmp_buf, int)
+VCHECK_2(longjmp, jmp_buf, int)
/***
restores the environment of a previous call to FUNCTION(setjmp)
diff --git a/src/signal/__signal.c b/src/signal/__signal.c
index e8c37e58..d4a819c6 100644
--- a/src/signal/__signal.c
+++ b/src/signal/__signal.c
@@ -1,6 +1,6 @@
#include "_signal.h"
-struct __signal __signal = {0};
+struct __signal ___signal = {0};
/*
STDC(0)
diff --git a/src/signal/__signal_handler.c b/src/signal/__signal_handler.c
index 985fa393..ca529999 100644
--- a/src/signal/__signal_handler.c
+++ b/src/signal/__signal_handler.c
@@ -4,12 +4,12 @@
void __signal_handler(int sig)
{
- __signal.current = sig;
- if (__signal.handlers[sig] != NULL) {
- __signal.handlers[sig](sig);
+ ___signal.current = sig;
+ if (___signal.handlers[sig] != NULL) {
+ ___signal.handlers[sig](sig);
}
/* TODO: if signal is fatal, trigger UB */
- __signal.current = 0;
+ ___signal.current = 0;
}
/*
diff --git a/src/signal/_signal.h b/src/signal/_signal.h
index 63490b2c..40a01fa0 100644
--- a/src/signal/_signal.h
+++ b/src/signal/_signal.h
@@ -10,7 +10,7 @@ typedef void (*handler)(int);
extern struct __signal {
int current;
handler handlers[NSIGNALS];
-} __signal;
+} ___signal;
void __signal_handler(int);
diff --git a/src/signal/signal.c b/src/signal/signal.c
index 07fb5ce0..4172c6da 100644
--- a/src/signal/signal.c
+++ b/src/signal/signal.c
@@ -22,7 +22,7 @@
void (*signal(int sig, void (*func)(int)))(int)
{
/* signal safe iff we are resetting the current signal handler */
- SIGNAL_SAFE((__signal.current == sig));
+ SIGNAL_SAFE((___signal.current == sig));
if (sig < 0 || sig > NSIGNALS) {
/* FIXME: should errno be set? */
@@ -31,8 +31,8 @@ void (*signal(int sig, void (*func)(int)))(int)
/* TODO: install __signal_handler as a hook */
- void (*prev)(int) = __signal.handlers[sig];
- __signal.handlers[sig] = func;
+ void (*prev)(int) = ___signal.handlers[sig];
+ ___signal.handlers[sig] = func;
struct linux_sigaction act = { 0 };
act.sa_handler = __signal_handler;
@@ -48,7 +48,7 @@ void (*signal(int sig, void (*func)(int)))(int)
}
typedef void (*handler)(int);
-//__check_2(handler, SIG_ERR, signal, int, handler)
+CHECK_2(handler, SIG_ERR, signal, int, handler)
/***
sets the signal handler for the signal specified by ARGUMENT(sig) to
diff --git a/src/stdio/__printf.c b/src/stdio/__printf.c
index 391f7cbc..e1460dfa 100644
--- a/src/stdio/__printf.c
+++ b/src/stdio/__printf.c
@@ -12,7 +12,7 @@
#include <stdlib.h>
#include "_stdio.h"
-#if (!defined __STDC_VERSION__) || (__STDC_VERSION__ < 199909L)
+#if (!defined __STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
#include "stdint/intmax_t.h"
#include "stdint/uintmax_t.h"
#include "stdint/intptr_t.h"
diff --git a/src/stdlib/__stdlib.c b/src/stdlib/__stdlib.c
index a95b7ef7..d1006bec 100644
--- a/src/stdlib/__stdlib.c
+++ b/src/stdlib/__stdlib.c
@@ -1,5 +1,9 @@
#include "_stdlib.h"
+#if ! (__STDC_VERSION__ >= 201112 && defined __STDC_WANT_LIB_EXT1__)
+#define abort_handler_s __abort_handler_s
+#endif
+
struct __stdlib __stdlib = {
.constraint_handler = abort_handler_s,
};
diff --git a/src/stdlib/abort_handler_s.c b/src/stdlib/abort_handler_s.c
index 4b1e3f03..cff0d539 100644
--- a/src/stdlib/abort_handler_s.c
+++ b/src/stdlib/abort_handler_s.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-//#include <errno.h>
+#include <errno.h>
#include "errno/errno_t.h"
#include "_stdlib.h"
@@ -17,7 +17,7 @@ void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t err
/* TODO: map numbers to names as well */
printf("While handling signal %d: ", ci->signal);
}
- printf("Function %s()", ci->func);
+
if (__checked_call.file) {
printf(" (");
if (__checked_call.func) {