From a3e27d361919392eeb0086ed93b105d8301c7913 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 26 Jul 2022 19:31:06 +0200 Subject: user: move the POSIX-y stuff to the proper header files --- src/user/lib/include/bits/file.h | 9 +++++++++ src/user/lib/include/stdio.h | 18 ++++++++++++++++++ src/user/lib/include/stdlib.h | 5 +++++ src/user/lib/include/string.h | 1 + src/user/lib/include/unistd.h | 5 +++++ 5 files changed, 38 insertions(+) create mode 100644 src/user/lib/include/bits/file.h create mode 100644 src/user/lib/include/stdio.h create mode 100644 src/user/lib/include/stdlib.h create mode 100644 src/user/lib/include/string.h create mode 100644 src/user/lib/include/unistd.h (limited to 'src/user/lib/include') diff --git a/src/user/lib/include/bits/file.h b/src/user/lib/include/bits/file.h new file mode 100644 index 0000000..d37b7de --- /dev/null +++ b/src/user/lib/include/bits/file.h @@ -0,0 +1,9 @@ +#pragma once +#include +// TODO make opaque +struct libc_file { + int fd; + int pos; + bool eof; +}; +typedef struct libc_file libc_file; diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h new file mode 100644 index 0000000..291a194 --- /dev/null +++ b/src/user/lib/include/stdio.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include + +int printf(const char *fmt, ...); +int snprintf(char *str, size_t len, const char *fmt, ...); + +int _klogf(const char *fmt, ...); // for kernel debugging only + + +extern libc_file *const stdin, *const stdout; + +libc_file *file_open(const char *path, int flags); +libc_file *file_reopen(libc_file*, const char *path, int flags); +libc_file *file_clone(const libc_file*); +int file_read(libc_file*, char *buf, size_t len); +int file_write(libc_file*, const char *buf, size_t len); +void file_close(libc_file*); diff --git a/src/user/lib/include/stdlib.h b/src/user/lib/include/stdlib.h new file mode 100644 index 0000000..5916ebc --- /dev/null +++ b/src/user/lib/include/stdlib.h @@ -0,0 +1,5 @@ +#pragma once +#include + +void *malloc(size_t size); +void free(void *ptr); diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h new file mode 100644 index 0000000..e5c0255 --- /dev/null +++ b/src/user/lib/include/string.h @@ -0,0 +1 @@ +#include diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h new file mode 100644 index 0000000..4a30298 --- /dev/null +++ b/src/user/lib/include/unistd.h @@ -0,0 +1,5 @@ +#pragma once +#include // TODO only needed because of handle_t + +int fork(void); +int close(handle_t h); -- cgit v1.2.3