Fully implemented stdio.h!

This commit is contained in:
2024-10-26 14:39:41 +02:00
parent 96fdd9a9cb
commit 21c59b28f7
6 changed files with 133 additions and 12 deletions
+5
View File
@@ -1,6 +1,11 @@
#ifndef _FCNTL_H
#define _FCNTL_H
/* Standard file decriptors */
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
/* File access modes */
#define O_CREAT 0x0001 // Create if does not exist
#define O_RDONLY 0x0002 // Read only
+1
View File
@@ -53,6 +53,7 @@ int ungetc(int c, FILE* stream);
/* Line I/O */
char* fgets(char* str, int n, FILE* stream);
int fputs(const char* str, FILE* stream);
char* gets(char* str, int n);
int puts(const char* str);
/* TODO: Error handling
+9 -9
View File
@@ -35,14 +35,14 @@ inline int syscall(int nr, int a0, int a1, int a2, int a3, int a4) {
}
/* Syscall wrappers */
inline int _exit(int status) { return syscall(SYS_EXIT, status, 0, 0, 0, 0); }
inline int read(int fd, void* ptr, size_t count) { return syscall(SYS_READ, fd, (int)ptr, (int)count, 0, 0); }
inline int write(int fd, const void* ptr, size_t count) { return syscall(SYS_WRITE, fd, (int)ptr, (int)count, 0, 0); }
inline int open(const char* path, int oflag) { return syscall(SYS_OPEN, (int)path, oflag, 0, 0, 0); }
inline int close(int fd) { return syscall(SYS_CLOSE, fd, 0, 0, 0, 0); }
inline int seek(int fd, size_t offset, int whence) { return syscall(SYS_SEEK, fd, offset, whence, 0, 0); }
inline int _malloc(int size) { return syscall(SYS_MALLOC, size, 0, 0, 0, 0); }
inline int _free(void* ptr) { return syscall(SYS_FREE, (int)ptr, 0, 0, 0, 0); }
inline int _sleep(int t) { return syscall(SYS_SLEEP, t, 0, 0, 0, 0); }
static inline int _exit(int status) { return syscall(SYS_EXIT, status, 0, 0, 0, 0); }
static inline int read(int fd, void* ptr, size_t count) { return syscall(SYS_READ, fd, (int)ptr, (int)count, 0, 0); }
static inline int write(int fd, const void* ptr, size_t count) { return syscall(SYS_WRITE, fd, (int)ptr, (int)count, 0, 0); }
static inline int open(const char* path, int oflag) { return syscall(SYS_OPEN, (int)path, oflag, 0, 0, 0); }
static inline int close(int fd) { return syscall(SYS_CLOSE, fd, 0, 0, 0, 0); }
static inline int seek(int fd, size_t offset, int whence) { return syscall(SYS_SEEK, fd, offset, whence, 0, 0); }
static inline int _malloc(int size) { return syscall(SYS_MALLOC, size, 0, 0, 0, 0); }
static inline int _free(void* ptr) { return syscall(SYS_FREE, (int)ptr, 0, 0, 0, 0); }
static inline int _sleep(int t) { return syscall(SYS_SLEEP, t, 0, 0, 0, 0); }
#endif