summaryrefslogtreecommitdiffstats
path: root/base/file_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/file_util.cc')
-rw-r--r--base/file_util.cc20
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