diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 17:40:13 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 17:40:13 +0000 |
commit | 836f134c56bfa714217ca12a73482205c1480774 (patch) | |
tree | 5c5b9d938a712e09831bdd32022e1b3716c5fbdf /base/file_util.cc | |
parent | d46d6f3b80099ce0c630185a2e86b649bba49254 (diff) | |
download | chromium_src-836f134c56bfa714217ca12a73482205c1480774.zip chromium_src-836f134c56bfa714217ca12a73482205c1480774.tar.gz chromium_src-836f134c56bfa714217ca12a73482205c1480774.tar.bz2 |
Cross-platform wrappers for fopen, _wfopen_s, etc.
Patch by Paweł Hajdan jr <phajdan.jr@gmail.com>.
http://codereview.chromium.org/6005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r-- | base/file_util.cc | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index bec910b..09f8249 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -4,6 +4,8 @@ #include "base/file_util.h" +#include <stdio.h> + #include <fstream> #include "base/logging.h" @@ -269,23 +271,17 @@ bool ContentsEqual(const std::wstring& filename1, } bool ReadFileToString(const std::wstring& path, std::string* contents) { -#if defined(OS_WIN) - FILE* file; - errno_t err = _wfopen_s(&file, path.c_str(), L"rbS"); - if (err != 0) - return false; -#elif defined(OS_POSIX) - FILE* file = fopen(WideToUTF8(path).c_str(), "r"); - if (!file) + FILE* file = OpenFile(path, "rb"); + if (!file) { return false; -#endif + } char buf[1 << 16]; size_t len; while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { contents->append(buf, len); } - fclose(file); + CloseFile(file); return true; } @@ -298,5 +294,9 @@ bool GetFileSize(const std::wstring& file_path, int64* file_size) { return true; } +bool CloseFile(FILE* file) { + return fclose(file) == 0; +} + } // namespace |