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.
This commit is contained in:
Alex Luccisano
2024-11-20 14:11:46 -05:00
committed by Ryan Foster
parent abb8cdf0da
commit 935613816f

View File

@@ -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__