diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dfa7ca7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "photon/libc/sys/magenta/libmagenta"] + path = photon/libc/sys/magenta/libmagenta + url = https://gitlab.com/doorstuck/magenta/libmagenta.git diff --git a/photon/libc/stdio/fdopen.c b/photon/libc/stdio/fdopen.c new file mode 100644 index 0000000..d379308 --- /dev/null +++ b/photon/libc/stdio/fdopen.c @@ -0,0 +1,15 @@ +#include +#include +#include <__fio.h> + +FILE *fdopen(int fd, const char *mode) +{ + struct __io_file *fp = malloc(sizeof(*fp)); + int res = __fio_fdopen(fd, mode, fp); + if (res != 0) { + free(fp); + return NULL; + } + + return fp; +} diff --git a/photon/libc/stdio/fflush.c b/photon/libc/stdio/fflush.c new file mode 100644 index 0000000..47d2a28 --- /dev/null +++ b/photon/libc/stdio/fflush.c @@ -0,0 +1,13 @@ +#include +#include +#include <__fio.h> + +int fflush(FILE *fp) +{ + int res = __fio_flush(fp); + if (res != 0) { + return -1; + } + + return 0; +} diff --git a/photon/libc/stdio/fopen.c b/photon/libc/stdio/fopen.c new file mode 100644 index 0000000..e671015 --- /dev/null +++ b/photon/libc/stdio/fopen.c @@ -0,0 +1,15 @@ +#include +#include +#include <__fio.h> + +FILE *fopen(const char *path, const char *mode) +{ + struct __io_file *fp = malloc(sizeof(*fp)); + int res = __fio_fopen(path, mode, fp); + if (res != 0) { + free(fp); + return NULL; + } + + return fp; +} diff --git a/photon/libc/stdio/freopen.c b/photon/libc/stdio/freopen.c new file mode 100644 index 0000000..83c62a1 --- /dev/null +++ b/photon/libc/stdio/freopen.c @@ -0,0 +1,16 @@ +#include +#include +#include <__fio.h> + +FILE *freopen(const char *path, const char *mode, FILE *fp) +{ + int res = __fio_fclose(fp); + + res = __fio_fopen(path, mode, fp); + if (res != 0) { + free(fp); + return NULL; + } + + return fp; +} diff --git a/photon/libc/stdio/puts.c b/photon/libc/stdio/puts.c index 9f17894..00b7a3e 100644 --- a/photon/libc/stdio/puts.c +++ b/photon/libc/stdio/puts.c @@ -2,5 +2,10 @@ int puts(const char *str) { - return fputs(str, stdout); + int ret = fputs(str, stdout); + if (ret < 0) { + return ret; + } + + return fputc('\n', stdout); } diff --git a/photon/libc/sys/magenta/libmagenta b/photon/libc/sys/magenta/libmagenta new file mode 160000 index 0000000..f0dfb73 --- /dev/null +++ b/photon/libc/sys/magenta/libmagenta @@ -0,0 +1 @@ +Subproject commit f0dfb732f86b80e60db863efdd2609a4c9bc5ce2