From 1161633db54ce8fd1180649f52909390a2986213 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 5 Jun 2024 15:07:06 -0400 Subject: rename all per-header internal structs to __
_h --- src/stdlib/__stdlib.c | 12 ------------ src/stdlib/__stdlib_h.c | 12 ++++++++++++ src/stdlib/_stdlib.h | 6 ++---- src/stdlib/at_quick_exit.c | 2 +- src/stdlib/atexit.c | 2 +- src/stdlib/exit.c | 12 ++++++------ src/stdlib/getenv.c | 6 +++--- src/stdlib/quick_exit.c | 12 ++++++------ src/stdlib/rand.c | 2 +- src/stdlib/srand.c | 2 +- 10 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 src/stdlib/__stdlib.c create mode 100644 src/stdlib/__stdlib_h.c (limited to 'src/stdlib') diff --git a/src/stdlib/__stdlib.c b/src/stdlib/__stdlib.c deleted file mode 100644 index 10117f1e..00000000 --- a/src/stdlib/__stdlib.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "_stdlib.h" - -struct __stdlib __stdlib = { - #if __STDC_VERSION__ >= 201112 && defined __STDC_WANT_LIB_EXT1__ - .constraint_handler = abort_handler_s, - #endif -}; - -/* -STDC(0) -SIGNAL_SAFE(0) -*/ diff --git a/src/stdlib/__stdlib_h.c b/src/stdlib/__stdlib_h.c new file mode 100644 index 00000000..dd277546 --- /dev/null +++ b/src/stdlib/__stdlib_h.c @@ -0,0 +1,12 @@ +#include "_stdlib.h" + +struct __stdlib_h __stdlib_h = { + #if __STDC_VERSION__ >= 201112 && defined __STDC_WANT_LIB_EXT1__ + .constraint_handler = abort_handler_s, + #endif +}; + +/* +STDC(0) +SIGNAL_SAFE(0) +*/ diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h index d5f89b09..64e64abd 100644 --- a/src/stdlib/_stdlib.h +++ b/src/stdlib/_stdlib.h @@ -53,7 +53,7 @@ static int __safe_compar(int (*compar)(const void *, const void *), const void * #include "__constraint_info.h" void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error); -struct __stdlib { +extern struct __stdlib_h { struct atexit { int nfns; void (*fns[32])(void); @@ -64,9 +64,7 @@ struct __stdlib { unsigned int rand; constraint_handler_t constraint_handler; char **environ; -}; - -extern struct __stdlib __stdlib; +} __stdlib_h; #ifdef _POSIX_SOURCE extern char **environ; diff --git a/src/stdlib/at_quick_exit.c b/src/stdlib/at_quick_exit.c index 6a6db796..d23dfda8 100644 --- a/src/stdlib/at_quick_exit.c +++ b/src/stdlib/at_quick_exit.c @@ -8,7 +8,7 @@ int at_quick_exit(void (*func)(void)) { SIGNAL_SAFE(0); - struct atexit *ae = &(__stdlib.at_quick_exit); + struct atexit *ae = &(__stdlib_h.at_quick_exit); while (ae->nfns == sizeof(ae->fns) / sizeof(ae->fns[0])) { if (ae->next == NULL) { ae->next = calloc(1, sizeof(*ae->next)); diff --git a/src/stdlib/atexit.c b/src/stdlib/atexit.c index d4b54c5f..e1d57df4 100644 --- a/src/stdlib/atexit.c +++ b/src/stdlib/atexit.c @@ -6,7 +6,7 @@ int atexit(void (*func)(void)) { - struct atexit *ae = &(__stdlib.atexit); + struct atexit *ae = &(__stdlib_h.atexit); SIGNAL_SAFE(0); diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c index e6423891..928c4423 100644 --- a/src/stdlib/exit.c +++ b/src/stdlib/exit.c @@ -8,17 +8,17 @@ /** cause normal program termination **/ _Noreturn void exit(int status) { - struct atexit *ae = &(__stdlib.atexit); + struct atexit *ae = &(__stdlib_h.atexit); SIGNAL_SAFE(0); - if (__stdlib.exit_called == QUICK) { - __stdlib.constraint_handler("Undefined behavior: exit() called after quick_exit()", NULL, 0); + if (__stdlib_h.exit_called == QUICK) { + __stdlib_h.constraint_handler("Undefined behavior: exit() called after quick_exit()", NULL, 0); } - if (__stdlib.exit_called == REGULAR) { - __stdlib.constraint_handler("Undefined behavior: exit() called twice", NULL, 0); + if (__stdlib_h.exit_called == REGULAR) { + __stdlib_h.constraint_handler("Undefined behavior: exit() called twice", NULL, 0); } - __stdlib.exit_called = REGULAR; + __stdlib_h.exit_called = REGULAR; /* execute all atexit() registered functions in reverse order */ while (ae) { diff --git a/src/stdlib/getenv.c b/src/stdlib/getenv.c index 5ef8f6a9..a2747998 100644 --- a/src/stdlib/getenv.c +++ b/src/stdlib/getenv.c @@ -17,10 +17,10 @@ char * getenv(const char * name) } len = strlen(name); - for (i = 0; __stdlib.environ[i] != NULL; i++) { - if (!strncmp(__stdlib.environ[i], name, len) && __stdlib.environ[i][len] == '=') { + for (i = 0; __stdlib_h.environ[i] != NULL; i++) { + if (!strncmp(__stdlib_h.environ[i], name, len) && __stdlib_h.environ[i][len] == '=') { __readonly(RO_UNLOCK, variable); - strcpy(variable, __stdlib.environ[i] + len + 1); + strcpy(variable, __stdlib_h.environ[i] + len + 1); __readonly(RO_LOCK, variable); return variable; } diff --git a/src/stdlib/quick_exit.c b/src/stdlib/quick_exit.c index 9ad6780e..59039e7b 100644 --- a/src/stdlib/quick_exit.c +++ b/src/stdlib/quick_exit.c @@ -7,16 +7,16 @@ _Noreturn void quick_exit(int status) { SIGNAL_SAFE(1); - if (__stdlib.exit_called == QUICK) { - __stdlib.constraint_handler("Undefined behavior: quick_exit() called twice", NULL, 0); + if (__stdlib_h.exit_called == QUICK) { + __stdlib_h.constraint_handler("Undefined behavior: quick_exit() called twice", NULL, 0); } - if (__stdlib.exit_called) { - __stdlib.constraint_handler("Undefined behavior: quick_exit() called after exit", NULL, 0); + if (__stdlib_h.exit_called) { + __stdlib_h.constraint_handler("Undefined behavior: quick_exit() called after exit", NULL, 0); } - __stdlib.exit_called = QUICK; + __stdlib_h.exit_called = QUICK; /* execute all at_quick_exit() registered functions in reverse order */ - struct atexit *ae = &(__stdlib.at_quick_exit); + struct atexit *ae = &(__stdlib_h.at_quick_exit); while (ae) { int i = ae->nfns; while (i > 0) { diff --git a/src/stdlib/rand.c b/src/stdlib/rand.c index a68dc046..00670dd5 100644 --- a/src/stdlib/rand.c +++ b/src/stdlib/rand.c @@ -5,7 +5,7 @@ int rand(void) { SIGNAL_SAFE(0); - return (int)_rand(__stdlib.rand); + return (int)_rand(__stdlib_h.rand); } /*** diff --git a/src/stdlib/srand.c b/src/stdlib/srand.c index 0870de9b..31f37a48 100644 --- a/src/stdlib/srand.c +++ b/src/stdlib/srand.c @@ -6,7 +6,7 @@ void srand(unsigned int seed) { SIGNAL_SAFE(0); - __stdlib.rand = seed; + __stdlib_h.rand = seed; } /*** -- cgit v1.2.1