mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
Userland: Use CFile in dmesg
This commit is contained in:
parent
7de861bdd9
commit
decf1afbaa
1 changed files with 7 additions and 18 deletions
|
@ -2,30 +2,19 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <LibCore/CFile.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) argc;
|
(void) argc;
|
||||||
(void) argv;
|
(void) argv;
|
||||||
int fd = open("/proc/dmesg", O_RDONLY);
|
CFile f("/proc/dmesg");
|
||||||
if (fd < 0) {
|
if (!f.open(CIODevice::ReadOnly)) {
|
||||||
perror("open /proc/dmesg");
|
fprintf(stderr, "open: failed to open /proc/dmesg: %s", f.error_string());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
for (;;) {
|
const auto& b = f.read_all();
|
||||||
char buffer[BUFSIZ];
|
for (auto i = 0; i < b.size(); ++i)
|
||||||
ssize_t nread = read(fd, buffer, sizeof(buffer));
|
putchar(b[i]);
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue