| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 | 6 |
| 7 #include <stdio.h> |
| 8 |
| 7 #include <fstream> | 9 #include <fstream> |
| 8 | 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 11 #include "unicode/uniset.h" | 13 #include "unicode/uniset.h" |
| 12 | 14 |
| 13 namespace file_util { | 15 namespace file_util { |
| 14 | 16 |
| 15 const wchar_t kExtensionSeparator = L'.'; | 17 const wchar_t kExtensionSeparator = L'.'; |
| 16 | 18 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 return false; | 264 return false; |
| 263 } | 265 } |
| 264 } while (!file1.eof() && !file2.eof()); | 266 } while (!file1.eof() && !file2.eof()); |
| 265 | 267 |
| 266 file1.close(); | 268 file1.close(); |
| 267 file2.close(); | 269 file2.close(); |
| 268 return true; | 270 return true; |
| 269 } | 271 } |
| 270 | 272 |
| 271 bool ReadFileToString(const std::wstring& path, std::string* contents) { | 273 bool ReadFileToString(const std::wstring& path, std::string* contents) { |
| 272 #if defined(OS_WIN) | 274 FILE* file = OpenFile(path, "rb"); |
| 273 FILE* file; | 275 if (!file) { |
| 274 errno_t err = _wfopen_s(&file, path.c_str(), L"rbS"); | |
| 275 if (err != 0) | |
| 276 return false; | 276 return false; |
| 277 #elif defined(OS_POSIX) | 277 } |
| 278 FILE* file = fopen(WideToUTF8(path).c_str(), "r"); | |
| 279 if (!file) | |
| 280 return false; | |
| 281 #endif | |
| 282 | 278 |
| 283 char buf[1 << 16]; | 279 char buf[1 << 16]; |
| 284 size_t len; | 280 size_t len; |
| 285 while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { | 281 while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { |
| 286 contents->append(buf, len); | 282 contents->append(buf, len); |
| 287 } | 283 } |
| 288 fclose(file); | 284 CloseFile(file); |
| 289 | 285 |
| 290 return true; | 286 return true; |
| 291 } | 287 } |
| 292 | 288 |
| 293 bool GetFileSize(const std::wstring& file_path, int64* file_size) { | 289 bool GetFileSize(const std::wstring& file_path, int64* file_size) { |
| 294 FileInfo info; | 290 FileInfo info; |
| 295 if (!GetFileInfo(file_path, &info)) | 291 if (!GetFileInfo(file_path, &info)) |
| 296 return false; | 292 return false; |
| 297 *file_size = info.size; | 293 *file_size = info.size; |
| 298 return true; | 294 return true; |
| 299 } | 295 } |
| 300 | 296 |
| 297 bool CloseFile(FILE* file) { |
| 298 return fclose(file) == 0; |
| 299 } |
| 300 |
| 301 } // namespace | 301 } // namespace |
| 302 | 302 |
| OLD | NEW |