hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/user/chat.c
blob: 7a1d5c856b69a58c58f32bd0c2fc12925ee5977a (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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char** argv)
{
    if (argc < 2)
    {
        printf("usage: run chat <path>\n");
        return 1;
    }

    const char* path = argv[1];
    int fd = open(path, O_RDONLY);
    if (fd < 0)
    {
        printf("chat: %s: cannot open\n", path);
        return 1;
    }

    char buffer[256];
    long bytes_read;
    while ((bytes_read = read(fd, buffer, sizeof(buffer))) > 0)
        write(1, buffer, (unsigned long)bytes_read);

    close(fd);
    return 0;
}