Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4181>
static uint64_t
get_available_system_memory()
{
- char *meminfo = os_read_file("/proc/meminfo");
+ char *meminfo = os_read_file("/proc/meminfo", NULL);
if (!meminfo)
return 0;
}
char *
-os_read_file(const char *filename)
+os_read_file(const char *filename, size_t *size)
{
/* Note that this also serves as a slight margin to avoid a 2x grow when
* the file is just a few bytes larger when we read it than when we
buf[offset] = '\0';
+ if (size)
+ *size = offset;
+
return buf;
}
#include "u_debug.h"
char *
-os_read_file(const char *filename)
+os_read_file(const char *filename, size_t *size)
{
errno = -ENOSYS;
return NULL;
/*
* Read a file.
* Returns a char* that the caller must free(), or NULL and sets errno.
+ * If size is not null and no error occured it's set to the size of the
+ * file.
*/
char *
-os_read_file(const char *filename);
+os_read_file(const char *filename, size_t *size);
/*
* Try to determine if two file descriptors reference the same file description