From aba76af848789d9f17d9f39b2dccad86b65725a1 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 22 May 2020 22:49:31 +0100 Subject: [PATCH] Refactor ReadAll() for strings to support linux /proc files * These files have no byte sizes so we can't seek to the end and start. We need to instead just read them chunk-wise. --- renderdoc/os/os_specific.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/renderdoc/os/os_specific.h b/renderdoc/os/os_specific.h index 1a4a5eb93..092092c06 100644 --- a/renderdoc/os/os_specific.h +++ b/renderdoc/os/os_specific.h @@ -381,17 +381,18 @@ inline bool ReadAll(const rdcstr &filename, rdcstr &str) if(f == NULL) return false; - FileIO::fseek64(f, 0, SEEK_END); - uint64_t size = ftell64(f); - FileIO::fseek64(f, 0, SEEK_SET); + char chunk[513]; - str.resize((size_t)size); - - size_t numRead = FileIO::fread(&str[0], 1, str.size(), f); + while(!FileIO::feof(f)) + { + memset(chunk, 0, 513); + size_t numRead = FileIO::fread(chunk, 1, 512, f); + str.append(chunk, numRead); + } FileIO::fclose(f); - return numRead == str.size(); + return true; } };