hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/user/chat.c
blob: 67bc727a291cabefaa6da82350e69bf44cd77889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
}