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

Side by Side Diff: base/file_util_win.cc

Issue 2253001: Revert 48186, 48196, 48198 (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/event_trace_provider_win_unittest.cc ('k') | base/iat_patch.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <propvarutil.h> 8 #include <propvarutil.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 ScopedHandle file(CreateFile(filename.value().c_str(), 649 ScopedHandle file(CreateFile(filename.value().c_str(),
650 GENERIC_READ, 650 GENERIC_READ,
651 FILE_SHARE_READ | FILE_SHARE_WRITE, 651 FILE_SHARE_READ | FILE_SHARE_WRITE,
652 NULL, 652 NULL,
653 OPEN_EXISTING, 653 OPEN_EXISTING,
654 FILE_FLAG_SEQUENTIAL_SCAN, 654 FILE_FLAG_SEQUENTIAL_SCAN,
655 NULL)); 655 NULL));
656 if (file == INVALID_HANDLE_VALUE) 656 if (file == INVALID_HANDLE_VALUE)
657 return -1; 657 return -1;
658 658
659 int ret_value;
659 DWORD read; 660 DWORD read;
660 if (::ReadFile(file, data, size, &read, NULL) && 661 if (::ReadFile(file, data, size, &read, NULL) && read == size) {
661 static_cast<int>(read) == size) 662 ret_value = static_cast<int>(read);
662 return read; 663 } else {
663 return -1; 664 ret_value = -1;
665 }
666
667 return ret_value;
664 } 668 }
665 669
666 int WriteFile(const FilePath& filename, const char* data, int size) { 670 int WriteFile(const FilePath& filename, const char* data, int size) {
667 ScopedHandle file(CreateFile(filename.value().c_str(), 671 ScopedHandle file(CreateFile(filename.value().c_str(),
668 GENERIC_WRITE, 672 GENERIC_WRITE,
669 0, 673 0,
670 NULL, 674 NULL,
671 CREATE_ALWAYS, 675 CREATE_ALWAYS,
672 0, 676 0,
673 NULL)); 677 NULL));
674 if (file == INVALID_HANDLE_VALUE) { 678 if (file == INVALID_HANDLE_VALUE) {
675 LOG(WARNING) << "CreateFile failed for path " << filename.value() << 679 LOG(WARNING) << "CreateFile failed for path " << filename.value() <<
676 " error code=" << GetLastError() << 680 " error code=" << GetLastError() <<
677 " error text=" << win_util::FormatLastWin32Error(); 681 " error text=" << win_util::FormatLastWin32Error();
678 return -1; 682 return -1;
679 } 683 }
680 684
681 DWORD written; 685 DWORD written;
682 BOOL result = ::WriteFile(file, data, size, &written, NULL); 686 BOOL result = ::WriteFile(file, data, size, &written, NULL);
683 if (result && static_cast<int>(written) == size) 687 if (result && written == size)
684 return written; 688 return static_cast<int>(written);
685 689
686 if (!result) { 690 if (!result) {
687 // WriteFile failed. 691 // WriteFile failed.
688 LOG(WARNING) << "writing file " << filename.value() << 692 LOG(WARNING) << "writing file " << filename.value() <<
689 " failed, error code=" << GetLastError() << 693 " failed, error code=" << GetLastError() <<
690 " description=" << win_util::FormatLastWin32Error(); 694 " description=" << win_util::FormatLastWin32Error();
691 } else { 695 } else {
692 // Didn't write all the bytes. 696 // Didn't write all the bytes.
693 LOG(WARNING) << "wrote" << written << " bytes to " << 697 LOG(WARNING) << "wrote" << written << " bytes to " <<
694 filename.value() << " expected " << size; 698 filename.value() << " expected " << size;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 } 899 }
896 900
897 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, 901 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info,
898 const base::Time& cutoff_time) { 902 const base::Time& cutoff_time) {
899 long result = CompareFileTime(&find_info.ftLastWriteTime, 903 long result = CompareFileTime(&find_info.ftLastWriteTime,
900 &cutoff_time.ToFileTime()); 904 &cutoff_time.ToFileTime());
901 return result == 1 || result == 0; 905 return result == 1 || result == 0;
902 } 906 }
903 907
904 } // namespace file_util 908 } // namespace file_util
OLDNEW
« no previous file with comments | « base/event_trace_provider_win_unittest.cc ('k') | base/iat_patch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698