Compare commits

...

4 Commits

6 changed files with 51 additions and 5 deletions

6
src/fcntl.c Normal file
View File

@ -0,0 +1,6 @@
#include <fcntl.h>
#include <liblinux.h>
int open(const char *path, int oflag, ...) {
return sys_open(path, oflag); // FIXME
}

6
src/include/fcntl.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _FCNTL_H
#define _FCNTL_H
int open(const char *path, int oflag, ...);
#endif

7
src/include/sys/types.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
typedef long int off_t;
typedef long ssize_t;
#endif

11
src/include/unistd.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _UNISTD_H
#define _UNISTD_H
#include <stddef.h>
#include <sys/types.h>
ssize_t read(int fildes, void *buf, size_t nbyte);
ssize_t write(int fildes, const void *buf, size_t nbyte);
int close(int fildes);
#endif

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;
}

14
src/unistd.c Normal file
View File

@ -0,0 +1,14 @@
#include <unistd.h>
#include <liblinux.h>
ssize_t read(int fildes, void *buf, size_t nbyte) {
return sys_read(fildes, buf, nbyte);
}
ssize_t write(int fildes, const void *buf, size_t nbyte) {
return sys_write(fildes, buf, nbyte);
}
int close(int fildes) {
return sys_close(fildes);
}