diff options
author | kaliamoorthi@chromium.org <kaliamoorthi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-18 16:31:51 +0000 |
---|---|---|
committer | kaliamoorthi@chromium.org <kaliamoorthi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-18 16:31:51 +0000 |
commit | 0710fdd560c67f86874fd797c081c7fd032bdef5 (patch) | |
tree | 0c733c8eae72b95166f52bfaf1e88407f80289ed /base/file_util.h | |
parent | 68d3fc19891f9864040264e6d6657720b886ac59 (diff) | |
download | chromium_src-0710fdd560c67f86874fd797c081c7fd032bdef5.zip chromium_src-0710fdd560c67f86874fd797c081c7fd032bdef5.tar.gz chromium_src-0710fdd560c67f86874fd797c081c7fd032bdef5.tar.bz2 |
Added new ReadFileToString API with a max_size argument
The CL creates a new API that takes a max_size argument. When the file size exceed the max_size, the API primes the cache and returns false.
BUG=339417
Review URL: https://codereview.chromium.org/157593005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251771 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.h')
-rw-r--r-- | base/file_util.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/base/file_util.h b/base/file_util.h index 7690703..9143c60 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -139,10 +139,24 @@ BASE_EXPORT bool TextContentsEqual(const FilePath& filename1, // Read the file at |path| into |contents|, returning true on success. // This function fails if the |path| contains path traversal components ('..'). // |contents| may be NULL, in which case this function is useful for its -// side effect of priming the disk cache. -// Useful for unit tests. +// side effect of priming the disk cache, which is useful for unit tests. +// The function replaces rather than append to |contents|, further |contents| +// could be cleared on error. BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); +// Read the file at |path| into |contents|, returning true on success. +// This function has an additional check on the maximum size of the file. +// When the file size is greater than |max_size|, the function reads |max_size| +// bytes into |contents| and returns false. +// This function fails if the |path| contains path traversal components ('..'). +// |contents| may be NULL, in which case this function is useful for its +// side effect of priming the disk cache, which is useful for unit tests. +// The function replaces rather than append to |contents|, further |contents| +// could be cleared on error. +BASE_EXPORT bool ReadFileToString(const FilePath& path, + std::string* contents, + size_t max_size); + #if defined(OS_POSIX) // Read exactly |bytes| bytes from file descriptor |fd|, storing the result |