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:
parent
12bcb703a5
commit
1697713301
12
src/stdio.c
12
src/stdio.c
|
@ -1,5 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define O_RDWR 2 // FIXME
|
#define O_RDWR 2 // FIXME
|
||||||
#define O_RDONLY 0
|
#define O_RDONLY 0
|
||||||
|
@ -36,7 +38,7 @@ FILE* fopen(const char *restrict pathname, const char *restrict mode) { // FIXME
|
||||||
default:
|
default:
|
||||||
return (FILE*)EINVAL;
|
return (FILE*)EINVAL;
|
||||||
}
|
}
|
||||||
int fd = sys_open(pathname, oflag);
|
int fd = open(pathname, oflag);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
FILE *temp = malloc(sizeof(pathname) + sizeof(fd));
|
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) {
|
int fclose(FILE *stream) {
|
||||||
return sys_close(stream->fd);
|
return close(stream->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fgetc(FILE *stream) {
|
int fgetc(FILE *stream) {
|
||||||
char buf = '\0';
|
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;
|
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) {
|
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) {
|
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) {
|
int putchar(int c) {
|
||||||
sys_write(stdout->fd, &c, 1);
|
write(stdout->fd, &c, 1);
|
||||||
return (unsigned char)c;
|
return (unsigned char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue