Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Unified Diff: base/file_util.cc

Issue 6005: Cross-platform equivalent of fopen, _wfopen_s etc.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/file_util.cc
===================================================================
--- base/file_util.cc (revision 2711)
+++ base/file_util.cc (working copy)
@@ -4,6 +4,8 @@
#include "base/file_util.h"
+#include <stdio.h>
+
#include <fstream>
#include "base/logging.h"
@@ -269,23 +271,17 @@
}
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)
+ FILE* file = OpenFile(path, "rb");
+ if (!file) {
return false;
-#elif defined(OS_POSIX)
- FILE* file = fopen(WideToUTF8(path).c_str(), "r");
- 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 @@
return true;
}
+bool CloseFile(FILE* file) {
+ return fclose(file) == 0;
+}
+
} // namespace
« no previous file with comments | « base/file_util.h ('k') | base/file_util_posix.cc » ('j') | base/file_util_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698