spl

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 56ddd02d7512c7cdc6b0e34f4576c185f410aec8
parent e2482b85232411aea48dd00a6845a6e336d1d8ad
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri, 20 Oct 2023 16:24:41 -0700

library: minimal file io: open/create/close/seek

Diffstat:
Mbootstrap/inc/library.impl.c | 22++++++++++++++++++++++
Mbootstrap/inc/library.impl.h | 6++++++
2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/bootstrap/inc/library.impl.c b/bootstrap/inc/library.impl.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <fcntl.h> void fn__hexout_(int x) { printf("D %08x\n", x); @@ -60,6 +61,27 @@ void fn_os_exit(int n) { exit(n); } +int fn_fd_open(t$str s) { + return open((void*)s, O_RDONLY, 0644); +} +int fn_fd_create(t$str s) { + return open((void*)s, O_RDWR | O_CREAT | O_TRUNC, 0644); +} +void fn_fd_close(int fd) { + close(fd); +} +int fn_fd_set_pos(int fd, unsigned pos) { + if (lseek(fd, pos, SEEK_SET) == ((off_t) -1)) { + return -1; + } else { + return 0; + } +} +unsigned fn_fd_get_pos(int fd) { + return lseek(fd, 0, SEEK_CUR); +} + void fn_abort(void) { abort(); } + diff --git a/bootstrap/inc/library.impl.h b/bootstrap/inc/library.impl.h @@ -9,6 +9,12 @@ void fn_writei(t$i32 fd, t$i32 n); void fn_writec(t$i32 fd, t$i32 c); t$i32 fn_readc(t$i32 fd); +t$i32 fn_fd_open(t$str s); +t$i32 fn_fd_create(t$str s); +void fn_fd_close(t$i32 fd); +t$i32 fn_fd_set_pos(t$i32 fd, t$u32 pos); +t$u32 fn_fd_get_pos(t$i32 fd); + t$u8* fn_os_arg(t$i32 n); t$i32 fn_os_arg_count(void); void fn_os_exit(t$i32 n);