summaryrefslogtreecommitdiff
path: root/Userland/dmesg.cpp
blob: 4f396a1b534cd5e7317975aa061e56b847669c0e (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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>

int main(int argc, char** argv)
{
    (void) argc;
    (void) argv;
    int fd = open("/proc/dmesg", O_RDONLY);
    if (fd < 0) {
        perror("open /proc/dmesg");
        return 1;
    }
    for (;;) {
        char buffer[BUFSIZ];
        ssize_t nread = read(fd, buffer, sizeof(buffer));
        if (nread < 0) {
            perror("read");
            return 1;
        }
        if (nread == 0) {
            break;
        }
        ssize_t nwritten = write(1, buffer, nread);
        assert(nwritten == nread);
    }
    int rc = close(fd);
    assert(rc == 0);
    return 0;
}