From 935613816fd8ed384ba86b035bd73af025258a11 Mon Sep 17 00:00:00 2001 From: Alex Luccisano Date: Wed, 20 Nov 2024 14:11:46 -0500 Subject: [PATCH] libobs/util: Update `os_get_free_size()` `os_get_free_size()` was simply returning 0. For Linux, implement the free size calculation based on the `sysinfo()` system call. --- libobs/util/platform-nix.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index bfcf4b560..6951df7a0 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -1032,11 +1032,6 @@ uint64_t os_get_proc_virtual_size(void) return (uint64_t)kinfo.ki_size; } #else -uint64_t os_get_sys_free_size(void) -{ - return 0; -} - typedef struct { unsigned long virtual_size; unsigned long resident_size; @@ -1116,6 +1111,20 @@ uint64_t os_get_sys_total_size(void) return total_memory; } + +uint64_t os_get_sys_free_size(void) +{ + uint64_t free_memory = 0; +#ifndef __OpenBSD__ + struct sysinfo info; + if (sysinfo(&info) < 0) + return 0; + + free_memory = ((uint64_t)info.freeram + (uint64_t)info.bufferram) * info.mem_unit; +#endif + + return free_memory; +} #endif #ifndef __APPLE__