Compare commits
4 Commits
050a684e57
...
1697713301
Author | SHA1 | Date |
---|---|---|
g1n | 1697713301 | |
g1n | 12bcb703a5 | |
g1n | 643baf8dec | |
g1n | 453745f6dd |
|
@ -0,0 +1,6 @@
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <liblinux.h>
|
||||||
|
|
||||||
|
int open(const char *path, int oflag, ...) {
|
||||||
|
return sys_open(path, oflag); // FIXME
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef _FCNTL_H
|
||||||
|
#define _FCNTL_H
|
||||||
|
|
||||||
|
int open(const char *path, int oflag, ...);
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef _SYS_TYPES_H
|
||||||
|
#define _SYS_TYPES_H
|
||||||
|
|
||||||
|
typedef long int off_t;
|
||||||
|
typedef long ssize_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -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
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue