Browse Source

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.
Alex Luccisano 11 months ago
parent
commit
935613816f
1 changed files with 14 additions and 5 deletions
  1. 14 5
      libobs/util/platform-nix.c

+ 14 - 5
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__