From e50b33d53795a5c8d95849347802e860deea55a6 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 10 Mar 2024 17:13:01 +0100 Subject: Avoid glibc FILE API for number of open files --- linux/Platform.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/linux/Platform.c b/linux/Platform.c index a47918fe..59fe7056 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -589,21 +589,21 @@ void Platform_getPressureStall(const char* file, bool some, double* ten, double* } void Platform_getFileDescriptors(double* used, double* max) { + char buffer[128] = {0}; + *used = NAN; *max = 65536; - FILE* fd = fopen(PROCDIR "/sys/fs/file-nr", "r"); - if (!fd) + ssize_t fdread = xReadfile(PROCDIR "/sys/fs/file-nr", buffer, sizeof(buffer)); + if (fdread < 1) return; unsigned long long v1, v2, v3; - int total = fscanf(fd, "%llu %llu %llu", &v1, &v2, &v3); + int total = sscanf(buffer, "%llu %llu %llu", &v1, &v2, &v3); if (total == 3) { *used = v1; *max = v3; } - - fclose(fd); } bool Platform_getDiskIO(DiskIOData* data) { -- cgit v1.2.3