Chromium Code Reviews| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #include <time.h> | 10 #include <time.h> |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 ULARGE_INTEGER size; | 440 ULARGE_INTEGER size; |
| 441 size.HighPart = attr.nFileSizeHigh; | 441 size.HighPart = attr.nFileSizeHigh; |
| 442 size.LowPart = attr.nFileSizeLow; | 442 size.LowPart = attr.nFileSizeLow; |
| 443 results->size = size.QuadPart; | 443 results->size = size.QuadPart; |
| 444 | 444 |
| 445 results->is_directory = | 445 results->is_directory = |
| 446 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 446 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 447 return true; | 447 return true; |
| 448 } | 448 } |
| 449 | 449 |
| 450 FILE* OpenFile(const std::string& filename, const char* mode) { | |
| 451 std::wstring w_mode = ASCIIToWide(std::string(mode)); | |
|
Mark Mentovai
2008/10/01 17:40:55
Not for fopen_s, you can just pass mode directly.
| |
| 452 FILE* file; | |
| 453 if (fopen_s(&file, filename.c_str(), w_mode.c_str()) != 0) { | |
| 454 return NULL; | |
| 455 } | |
| 456 return file; | |
| 457 } | |
| 458 | |
| 459 FILE* OpenFile(const std::wstring& filename, const char* mode) { | |
| 460 std::wstring w_mode = ASCIIToWide(std::string(mode)); | |
| 461 FILE* file; | |
| 462 if (_wfopen_s(&file, filename.c_str(), w_mode.c_str()) != 0) { | |
| 463 return NULL; | |
| 464 } | |
| 465 return file; | |
| 466 } | |
| 467 | |
| 450 int ReadFile(const std::wstring& filename, char* data, int size) { | 468 int ReadFile(const std::wstring& filename, char* data, int size) { |
| 451 ScopedHandle file(CreateFile(filename.c_str(), | 469 ScopedHandle file(CreateFile(filename.c_str(), |
| 452 GENERIC_READ, | 470 GENERIC_READ, |
| 453 FILE_SHARE_READ | FILE_SHARE_WRITE, | 471 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 454 NULL, | 472 NULL, |
| 455 OPEN_EXISTING, | 473 OPEN_EXISTING, |
| 456 FILE_FLAG_SEQUENTIAL_SCAN, | 474 FILE_FLAG_SEQUENTIAL_SCAN, |
| 457 NULL)); | 475 NULL)); |
| 458 if (file == INVALID_HANDLE_VALUE) | 476 if (file == INVALID_HANDLE_VALUE) |
| 459 return -1; | 477 return -1; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); | 674 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); |
| 657 } | 675 } |
| 658 | 676 |
| 659 if ((file_type_ & FileEnumerator::DIRECTORIES) == 0) | 677 if ((file_type_ & FileEnumerator::DIRECTORIES) == 0) |
| 660 return Next(); | 678 return Next(); |
| 661 } | 679 } |
| 662 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); | 680 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); |
| 663 } | 681 } |
| 664 | 682 |
| 665 } // namespace file_util | 683 } // namespace file_util |
| OLD | NEW |