mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-05 10:42:51 +00:00
LibGUI: Add GFile and base class GIODevice.
Working with the LibC API's is tedious, so let's add some comfy C++ API's.
This commit is contained in:
parent
ef05d8cbf6
commit
ce7017e1ec
Notes:
sideshowbarker
2024-07-19 15:01:12 +09:00
Author: https://github.com/awesomekling
Commit: ce7017e1ec
6 changed files with 230 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "ProcessTableModel.h"
|
||||
#include <LibGUI/GFile.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
@ -121,10 +122,11 @@ GVariant ProcessTableModel::data(const GModelIndex& index, Role role) const
|
|||
|
||||
void ProcessTableModel::update()
|
||||
{
|
||||
FILE* fp = fopen("/proc/all", "r");
|
||||
if (!fp) {
|
||||
perror("failed to open /proc/all");
|
||||
GFile file("/proc/all");
|
||||
if (!file.open(GIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "ProcessManager: Failed to open /proc/all: %s\n", file.error_string());
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned last_sum_nsched = 0;
|
||||
|
@ -134,11 +136,10 @@ void ProcessTableModel::update()
|
|||
HashTable<pid_t> live_pids;
|
||||
unsigned sum_nsched = 0;
|
||||
for (;;) {
|
||||
char buf[BUFSIZ];
|
||||
char* ptr = fgets(buf, sizeof(buf), fp);
|
||||
if (!ptr)
|
||||
auto line = file.read_line(1024);
|
||||
if (line.is_empty())
|
||||
break;
|
||||
auto parts = String(buf, Chomp).split(',');
|
||||
auto parts = String((const char*)line.pointer(), line.size() - 1, Chomp).split(',');
|
||||
if (parts.size() < 17)
|
||||
break;
|
||||
bool ok;
|
||||
|
@ -178,8 +179,6 @@ void ProcessTableModel::update()
|
|||
|
||||
live_pids.set(pid);
|
||||
}
|
||||
int rc = fclose(fp);
|
||||
ASSERT(rc == 0);
|
||||
|
||||
m_pids.clear();
|
||||
Vector<pid_t> pids_to_remove;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue