1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

Userland: Use CFile in mm

This commit is contained in:
Robin Burchell 2019-06-02 12:08:47 +02:00 committed by Andreas Kling
parent 9a4ec2e92a
commit 7de861bdd9

View file

@ -1,28 +1,20 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.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/mm", O_RDONLY);
if (fd == -1) { CFile f("/proc/mm");
perror("failed to open /proc/mm"); if (!f.open(CIODevice::ReadOnly)) {
fprintf(stderr, "open: failed to open /proc/mm: %s", f.error_string());
return 1; return 1;
} }
for (;;) { const auto& b = f.read_all();
char buf[128]; for (auto i = 0; i < b.size(); ++i)
ssize_t nread = read(fd, buf, sizeof(buf)); putchar(b[i]);
if (nread == 0)
break;
if (nread < 0) {
perror("failed to read");
return 2;
}
for (ssize_t i = 0; i < nread; ++i) {
putchar(buf[i]);
}
}
return 0; return 0;
} }