aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre-Eric Pelloux-Prayer <[email protected]>2020-03-16 10:48:48 +0100
committerPierre-Eric Pelloux-Prayer <[email protected]>2020-03-24 08:30:34 +0100
commit2cb965e5b60dbcd767da42360a5e18acd8803f5d (patch)
treea9170a0af658650b6f96eef16320bbb655b65491 /src
parentbd6234f24be024556a4b83e879bb65b89fea7a12 (diff)
util/os_file: extend os_read_file to return the file size
Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4181>
Diffstat (limited to 'src')
-rw-r--r--src/intel/vulkan/anv_device.c2
-rw-r--r--src/util/os_file.c7
-rw-r--r--src/util/os_file.h4
3 files changed, 9 insertions, 4 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index cffcecca75c..11fb4f6c3fc 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -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;
diff --git a/src/util/os_file.c b/src/util/os_file.c
index 228f1e823c5..5771b27e5d0 100644
--- a/src/util/os_file.c
+++ b/src/util/os_file.c
@@ -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;
diff --git a/src/util/os_file.h b/src/util/os_file.h
index 58639476f60..36f367ea358 100644
--- a/src/util/os_file.h
+++ b/src/util/os_file.h
@@ -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