mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-05-10 13:17:36 +00:00
Userland: Use CFile in dmesg
This commit is contained in:
committed by
Andreas Kling
parent
7de861bdd9
commit
decf1afbaa
@@ -2,30 +2,19 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <LibCore/CFile.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");
|
||||
CFile f("/proc/dmesg");
|
||||
if (!f.open(CIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "open: failed to open /proc/dmesg: %s", f.error_string());
|
||||
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);
|
||||
const auto& b = f.read_all();
|
||||
for (auto i = 0; i < b.size(); ++i)
|
||||
putchar(b[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user