From: Pierre-Eric Pelloux-Prayer Date: Mon, 16 Mar 2020 09:48:48 +0000 (+0100) Subject: util/os_file: extend os_read_file to return the file size X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2cb965e5b60dbcd767da42360a5e18acd8803f5d;p=mesa.git util/os_file: extend os_read_file to return the file size Reviewed-by: Marek Olšák Part-of: --- 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