diff options
| author | hachem <im@hachem.wtf> | 2026-10-12 23:08:48 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-12 23:08:48 +0200 |
| commit | 6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 (patch) | |
| tree | bb137b732a1d122aeace46c550733f4793d84601 /user/chat.c | |
| parent | 59794d0b999e544a94230d9562bf2b99d2ed74c7 (diff) | |
Diffstat (limited to 'user/chat.c')
| -rw-r--r-- | user/chat.c | 36 |
1 files changed, 16 insertions, 20 deletions
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 <stdio.h> +#include <unistd.h> +#include <fcntl.h> -void _start(const char* arg, unsigned long arglen) +int main(int argc, char** argv) { - if (arglen == 0) + if (argc < 2) { - put("usage: run chat <path>\n"); - sys_exit(1); + printf("usage: run chat <path>\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; } |
