From 6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 Mon Sep 17 00:00:00 2001 From: hachem Date: Mon, 12 Oct 2026 23:08:48 +0200 Subject: feat: lib sea --- user/chat.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'user/chat.c') diff --git a/user/chat.c b/user/chat.c index 1657c73..7a1d5c8 100644 --- a/user/chat.c +++ b/user/chat.c @@ -1,32 +1,28 @@ -#include "user.h" +#include +#include +#include -void _start(const char* arg, unsigned long arglen) +int main(int argc, char** argv) { - if (arglen == 0) + if (argc < 2) { - put("usage: run chat \n"); - sys_exit(1); + printf("usage: run chat \n"); + return 1; } - char path[128]; - unsigned long i = 0; - for (; i < arglen && i < sizeof(path) - 1; i++) - path[i] = arg[i]; - path[i] = 0; - - long fd = sys_open(path, 0); + const char* path = argv[1]; + int fd = open(path, O_RDONLY); if (fd < 0) { - put("chat: "); - put(path); - put(": cannot open\n"); - sys_exit(1); + printf("chat: %s: cannot open\n", path); + return 1; } char buffer[256]; long bytes_read; - while ((bytes_read = sys_read(fd, buffer, sizeof(buffer))) > 0) - (void)sys_write(1, buffer, (unsigned long)bytes_read); - (void)sys_close(fd); - sys_exit(0); + while ((bytes_read = read(fd, buffer, sizeof(buffer))) > 0) + write(1, buffer, (unsigned long)bytes_read); + + close(fd); + return 0; } -- cgit v1.3