Implemented a bunch of FILE stdio functions
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal 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
photon/libc/stdio/fdopen.c
Normal file
15
photon/libc/stdio/fdopen.c
Normal 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
photon/libc/stdio/fflush.c
Normal file
13
photon/libc/stdio/fflush.c
Normal 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
photon/libc/stdio/fopen.c
Normal file
15
photon/libc/stdio/fopen.c
Normal 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
photon/libc/stdio/freopen.c
Normal file
16
photon/libc/stdio/freopen.c
Normal 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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
1
photon/libc/sys/magenta/libmagenta
Submodule
1
photon/libc/sys/magenta/libmagenta
Submodule
Submodule photon/libc/sys/magenta/libmagenta added at f0dfb732f8
Reference in New Issue
Block a user