hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/user/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'user/chat.c')
-rw-r--r--user/chat.c36
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;
}