summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-31 01:19:23 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-31 01:19:23 -0500
commit0f649efceacd8f9eb921d5765dfa73b0771b1fcd (patch)
treefaadaeae5c3277435d97650fcc22be5203e17c35
parent28a7e3dfb4ca2bd407508ef789bf1859acd9b969 (diff)
use a single variable for tracking exit calls
-rw-r--r--src/stdlib/_stdlib.h3
-rw-r--r--src/stdlib/exit.c6
-rw-r--r--src/stdlib/quick_exit.c24
3 files changed, 16 insertions, 17 deletions
diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h
index de5a97d0..769f220b 100644
--- a/src/stdlib/_stdlib.h
+++ b/src/stdlib/_stdlib.h
@@ -20,8 +20,7 @@ struct __stdlib {
struct atexit *next;
struct atexit *prev;
} atexit, at_quick_exit;
- int exit_called;
- int quick_exit_called;
+ enum { REGULAR = 1, QUICK } exit_called;
unsigned int rand;
char **environ;
constraint_handler_t constraint_handler;
diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c
index cd3175d6..42af83c7 100644
--- a/src/stdlib/exit.c
+++ b/src/stdlib/exit.c
@@ -14,13 +14,13 @@ _Noreturn void exit(int status)
SIGNAL_SAFE(0);
- if (__stdlib.quick_exit_called) {
+ if (__stdlib.exit_called == QUICK) {
__stdlib.constraint_handler("Undefined behavior: exit() called after quick_exit()", NULL, 0);
}
- if (__stdlib.exit_called) {
+ if (__stdlib.exit_called == REGULAR) {
__stdlib.constraint_handler("Undefined behavior: exit() called twice", NULL, 0);
}
- __stdlib.exit_called = 1;
+ __stdlib.exit_called = REGULAR;
/* execute all atexit() registered functions in reverse order */
while (ae) {
diff --git a/src/stdlib/quick_exit.c b/src/stdlib/quick_exit.c
index 3d754604..9ad6780e 100644
--- a/src/stdlib/quick_exit.c
+++ b/src/stdlib/quick_exit.c
@@ -7,23 +7,23 @@ _Noreturn void quick_exit(int status)
{
SIGNAL_SAFE(1);
- if (__stdlib.quick_exit_called) {
+ if (__stdlib.exit_called == QUICK) {
__stdlib.constraint_handler("Undefined behavior: quick_exit() called twice", NULL, 0);
- }
- if (__stdlib.exit_called) {
+ }
+ if (__stdlib.exit_called) {
__stdlib.constraint_handler("Undefined behavior: quick_exit() called after exit", NULL, 0);
- }
- __stdlib.quick_exit_called = 1;
+ }
+ __stdlib.exit_called = QUICK;
/* execute all at_quick_exit() registered functions in reverse order */
struct atexit *ae = &(__stdlib.at_quick_exit);
- while (ae) {
- int i = ae->nfns;
- while (i > 0) {
- ae->fns[--i]();
- }
- ae = ae->prev;
- }
+ while (ae) {
+ int i = ae->nfns;
+ while (i > 0) {
+ ae->fns[--i]();
+ }
+ ae = ae->prev;
+ }
fflush(NULL);
// fclose(all the things);