diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/stdio/stdout.c | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/stdio/stdout.c')
| -rw-r--r-- | lib/libc/stdio/stdout.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/libc/stdio/stdout.c b/lib/libc/stdio/stdout.c new file mode 100644 index 00000000..7d55c3e7 --- /dev/null +++ b/lib/libc/stdio/stdout.c @@ -0,0 +1,34 @@ +#include <io.h> +#include <libc.h> +#include <fcntl.h> +#include <atomic.h> +#include <unistd.h> + +#define BUFSIZ 4096 + +weak char __stdout_buffer[0]; +static atomic_flag __stdio_lock = ATOMIC_FLAG_INIT; +struct __FILE __stdout = { .fd = STDOUT_FILENO, + .flags = O_WRONLY, + .type = 1, + .buf = __stdout_buffer, + .buf_len = 0, + .buf_size = BUFSIZ, + .buf_pos = 0, + .eof = 0, + .unget_cnt = 0, + .offset = 0, + .next = NULL, + .lock = ATOMIC_FLAG_INIT }; + +struct __FILE *const stdout = (struct __FILE *)&__stdout; + +void __libc_fadd(struct __FILE *f) +{ + LIBC_LOCK(__stdio_lock); + struct __FILE *cur = &__stdout; + while (cur->next) + cur = cur->next; + cur->next = f; + LIBC_UNLOCK(__stdio_lock); +} |
