util/os_file: extend os_read_file to return the file size

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4181>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-03-16 10:48:48 +01:00
parent bd6234f24b
commit 2cb965e5b6
3 changed files with 9 additions and 4 deletions

View file

@ -308,7 +308,7 @@ anv_physical_device_free_disk_cache(struct anv_physical_device *device)
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;

View file

@ -67,7 +67,7 @@ readN(int fd, char *buf, size_t len)
}
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
@ -130,6 +130,9 @@ os_read_file(const char *filename)
buf[offset] = '\0';
if (size)
*size = offset;
return buf;
}
@ -150,7 +153,7 @@ os_same_file_description(int fd1, int fd2)
#include "u_debug.h"
char *
os_read_file(const char *filename)
os_read_file(const char *filename, size_t *size)
{
errno = -ENOSYS;
return NULL;

View file

@ -27,9 +27,11 @@ os_file_create_unique(const char *filename, int filemode);
/*
* 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