mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
Userland: Use CFile in ps
This commit is contained in:
parent
e74b5975e4
commit
9a4ec2e92a
Notes:
sideshowbarker
2024-07-19 13:46:52 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/9a4ec2e92a9 Pull-request: https://github.com/SerenityOS/serenity/pull/167
1 changed files with 8 additions and 16 deletions
|
@ -1,28 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <LibCore/CFile.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue