Implemented a bunch of FILE stdio functions

This commit is contained in:
Max Wash
2020-05-13 20:36:06 +01:00
parent 113c3544f9
commit ff9937861b
7 changed files with 69 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "photon/libc/sys/magenta/libmagenta"]
path = photon/libc/sys/magenta/libmagenta
url = https://gitlab.com/doorstuck/magenta/libmagenta.git
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <__fio.h>
int fflush(FILE *fp)
{
int res = __fio_flush(fp);
if (res != 0) {
return -1;
}
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
+6 -1
View File
@@ -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);
}