summaryrefslogtreecommitdiff
path: root/Userland/dmesg.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-06-02 12:13:06 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-02 12:55:51 +0200
commitdecf1afbaa44d9083137675159ae2fc280f2b1ac (patch)
tree9c7abfbc814872903e3b4eb0afb9cc050c938dbd /Userland/dmesg.cpp
parent7de861bdd93dff92dd2ffa8b7b98ebc625cec003 (diff)
downloadserenity-decf1afbaa44d9083137675159ae2fc280f2b1ac.zip
Userland: Use CFile in dmesg
Diffstat (limited to 'Userland/dmesg.cpp')
-rw-r--r--Userland/dmesg.cpp25
1 files changed, 7 insertions, 18 deletions
diff --git a/Userland/dmesg.cpp b/Userland/dmesg.cpp
index 4f396a1b53..f8b3b48db1 100644
--- a/Userland/dmesg.cpp
+++ b/Userland/dmesg.cpp
@@ -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;
}