summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-22 23:27:56 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-22 23:30:32 +0100
commit0f30d227497418c6d3bef7d52244407e30454504 (patch)
tree0e1ac19623d3268380cf74328cdf643648a2f43c /lib/libc/stdlib
parent90dad97fc07f049383903a166631e2c257f9b8c1 (diff)
Added c11 threads, fixed some locks and add *_unlocked functions
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/exit.c51
-rw-r--r--lib/libc/stdlib/strtox.c12
2 files changed, 4 insertions, 59 deletions
diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c
index 7fc96f28..80054637 100644
--- a/lib/libc/stdlib/exit.c
+++ b/lib/libc/stdlib/exit.c
@@ -1,65 +1,14 @@
-#include "__stdio.h" // for __FILE
-#include "stddef.h" // for NULL
-
#include <libc.h> // for weak_reference
-#include <stdio.h> // for fflush, stdout, FILE, stderr, stdin
#include <stdlib.h> // for free, exit
#include <unistd.h> // for _exit, close, write, STDERR_FILENO
void (*__dummy_atexit_fvec)(void);
weak_reference(__dummy_atexit_fvec, __atexit_fvec);
-void (*__dummy_stdio_cleanup)(void);
-weak_reference(__dummy_stdio_cleanup, __stdio_cleanup);
-
-static void __fclose(FILE *stream)
-{
- if (stream == NULL) {
- return;
- }
-
- if (__FILE(stream)->buf_len > 0) {
- fflush(stream);
- }
-
- if (__FILE(stream)->fd > STDERR_FILENO) {
- close(__FILE(stream)->fd);
- }
-
- if (__FILE(stream)->buf) {
- free(__FILE(stream)->buf);
- }
-
- if (stream != stdout && stream != stderr && stream != stdin) {
- free(stream);
- }
-}
-
-static void __stdio_cleanup_impl(void)
-{
- write(1, "HELLO\n", 6);
- fflush(stdout);
-
- if (stdout->next != NULL) {
- FILE *cur = stdout->next;
- while (cur) {
- struct __FILE *next = cur->next;
- __fclose(cur);
- cur = next;
- }
- }
-}
-
void exit(int status)
{
void (*fptr)(void);
- /* Only do stdio cleanup if it was referenced (meaning stdio was used)
- */
- if (__stdio_cleanup) {
- __stdio_cleanup_impl();
- }
-
if (__atexit_fvec) {
fptr = __atexit_fvec;
while (fptr) {
diff --git a/lib/libc/stdlib/strtox.c b/lib/libc/stdlib/strtox.c
index b50a77a1..276b8c2e 100644
--- a/lib/libc/stdlib/strtox.c
+++ b/lib/libc/stdlib/strtox.c
@@ -6,8 +6,7 @@
#include <stdlib.h> // for strtof, strtol, strtold, strtoll, strtoul, strt...
#include <strings.h> // for strncasecmp
-static unsigned long long
-__scanint(const char *s, int base, unsigned long long lim, int *neg, char **end)
+static unsigned long long __scanint(const char *s, int base, unsigned long long lim, int *neg, char **end)
{
unsigned long long res = 0;
int digit, any = 0;
@@ -21,8 +20,7 @@ __scanint(const char *s, int base, unsigned long long lim, int *neg, char **end)
s++;
}
- if ((base == 0 || base == 16) && s[0] == '0' &&
- (s[1] == 'x' || s[1] == 'X')) {
+ if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
base = 16;
s += 2;
} else if (base == 0 && *s == '0') {
@@ -193,8 +191,7 @@ long long strtoll(const char *restrict nptr, char **restrict endptr, int base)
return (long long)v;
}
-unsigned long strtoul(const char *restrict nptr, char **restrict endptr,
- int base)
+unsigned long strtoul(const char *restrict nptr, char **restrict endptr, int base)
{
int neg;
unsigned long long v;
@@ -214,8 +211,7 @@ unsigned long strtoul(const char *restrict nptr, char **restrict endptr,
return (unsigned long)v;
}
-unsigned long long strtoull(const char *restrict nptr, char **restrict endptr,
- int base)
+unsigned long long strtoull(const char *restrict nptr, char **restrict endptr, int base)
{
int neg;
unsigned long long v;