From 9a4ec2e92a9ed07d776851cb84404cd3260b2f9d Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Sun, 2 Jun 2019 12:07:24 +0200 Subject: [PATCH] Userland: Use CFile in ps --- Userland/ps.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Userland/ps.cpp b/Userland/ps.cpp index 6b18f3a0f13..4fd0c4aa0a2 100644 --- a/Userland/ps.cpp +++ b/Userland/ps.cpp @@ -1,28 +1,20 @@ #include #include #include +#include int main(int argc, char** argv) { (void) argc; (void) argv; - int fd = open("/proc/summary", O_RDONLY); - if (fd == -1) { - perror("failed to open /proc/summary"); + + CFile f("/proc/summary"); + if (!f.open(CIODevice::ReadOnly)) { + fprintf(stderr, "open: failed to open /proc/summary: %s", f.error_string()); return 1; } - for (;;) { - char buf[128]; - ssize_t nread = read(fd, buf, sizeof(buf)); - if (nread == 0) - break; - if (nread < 0) { - perror("failed to read"); - return 2; - } - for (ssize_t i = 0; i < nread; ++i) { - putchar(buf[i]); - } - } + const auto& b = f.read_all(); + for (auto i = 0; i < b.size(); ++i) + putchar(b[i]); return 0; }