hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/user/chat.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-08 22:23:55 +0200
committerhachem <im@hachem.wtf>2026-10-08 22:23:55 +0200
commit852a5b237116e8b53ae18ea8ea00505e44b40dfe (patch)
tree1ed51afcf6471d2a0031d31b67b63f4ec404b9ed /user/chat.c
parentef104148057ab98f80b1560405b5c02768457096 (diff)
feat: file descriptor and proper stdio
Diffstat (limited to 'user/chat.c')
-rw-r--r--user/chat.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/user/chat.c b/user/chat.c
new file mode 100644
index 0000000..67bc727
--- /dev/null
+++ b/user/chat.c
@@ -0,0 +1,33 @@
+#include "user.h"
+
+void _start(const char* arg, unsigned long arglen)
+{
+ if (arglen == 0)
+ {
+ put("usage: run chat <path>\n");
+ sys_exit(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);
+ if (fd < 0)
+ {
+ put("chat: ");
+ put(path);
+ put(": cannot open\n");
+ sys_exit(1);
+ }
+
+ char buffer[256];
+ long n;
+ while ((n = sys_read(fd, buffer, sizeof(buffer))) > 0)
+ sys_write(1, buffer, (unsigned long)n);
+
+ sys_close(fd);
+ sys_exit(0);
+}