Changed <stdio.h> to use open, close, read and write functions from libc instead of directly using them from liblinux (might make porting process easier)

This commit is contained in:
g1n 2022-07-24 13:25:26 +03:00
parent 12bcb703a5
commit 1697713301
Signed by: g1n
GPG Key ID: 8D352193D65D4E2C
1 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#define O_RDWR 2 // FIXME
#define O_RDONLY 0
@ -36,7 +38,7 @@ FILE* fopen(const char *restrict pathname, const char *restrict mode) { // FIXME
default:
return (FILE*)EINVAL;
}
int fd = sys_open(pathname, oflag);
int fd = open(pathname, oflag);
if (fd == -1)
return NULL;
FILE *temp = malloc(sizeof(pathname) + sizeof(fd));
@ -46,12 +48,12 @@ FILE* fopen(const char *restrict pathname, const char *restrict mode) { // FIXME
}
int fclose(FILE *stream) {
return sys_close(stream->fd);
return close(stream->fd);
}
int fgetc(FILE *stream) {
char buf = '\0';
sys_read(stream->fd, (void*)&buf, 1);
read(stream->fd, (void*)&buf, 1);
return (buf == '\0') ? (unsigned int)-1 : (unsigned int)buf;
}
@ -68,7 +70,7 @@ char *fgets(char *restrict s, int n, FILE *restrict stream) {
}
int fputc(int c, FILE *stream) {
return (sys_write(stream->fd, &c, 1) == -1 ) ? -1 : c;
return (write(stream->fd, &c, 1) == -1 ) ? -1 : c;
}
int fputs(const char *restrict s, FILE *restrict stream) {
@ -85,7 +87,7 @@ int rename(const char *old, const char *new) {
}
int putchar(int c) {
sys_write(stdout->fd, &c, 1);
write(stdout->fd, &c, 1);
return (unsigned char)c;
}