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

Side by Side Diff: base/file_util_win.cc

Issue 240893002: base::ReadFile() should return the number of read bytes on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing parenthesis. Created 6 years, 8 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
« base/file_util_unittest.cc ('K') | « base/file_util_unittest.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <psapi.h> 8 #include <psapi.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 564
565 return true; 565 return true;
566 } 566 }
567 567
568 FILE* OpenFile(const FilePath& filename, const char* mode) { 568 FILE* OpenFile(const FilePath& filename, const char* mode) {
569 ThreadRestrictions::AssertIOAllowed(); 569 ThreadRestrictions::AssertIOAllowed();
570 std::wstring w_mode = ASCIIToWide(std::string(mode)); 570 std::wstring w_mode = ASCIIToWide(std::string(mode));
571 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); 571 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO);
572 } 572 }
573 573
574 int ReadFile(const FilePath& filename, char* data, int size) { 574 int ReadFile(const FilePath& filename, char* data, int max_size) {
575 ThreadRestrictions::AssertIOAllowed(); 575 ThreadRestrictions::AssertIOAllowed();
576 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), 576 base::win::ScopedHandle file(CreateFile(filename.value().c_str(),
577 GENERIC_READ, 577 GENERIC_READ,
578 FILE_SHARE_READ | FILE_SHARE_WRITE, 578 FILE_SHARE_READ | FILE_SHARE_WRITE,
579 NULL, 579 NULL,
580 OPEN_EXISTING, 580 OPEN_EXISTING,
581 FILE_FLAG_SEQUENTIAL_SCAN, 581 FILE_FLAG_SEQUENTIAL_SCAN,
582 NULL)); 582 NULL));
583 if (!file) 583 if (!file)
584 return -1; 584 return -1;
585 585
586 DWORD read; 586 DWORD read;
587 if (::ReadFile(file, data, size, &read, NULL) && 587 if (::ReadFile(file, data, max_size, &read, NULL))
Mark Mentovai 2014/04/17 16:21:57 The same concern about short non-EOF reads that I
fukino 2014/04/18 02:22:12 Yes. filed as http://crbug.com/364762.
588 static_cast<int>(read) == size)
589 return read; 588 return read;
589
590 return -1; 590 return -1;
591 } 591 }
592 592
593 int WriteFile(const FilePath& filename, const char* data, int size) { 593 int WriteFile(const FilePath& filename, const char* data, int size) {
594 ThreadRestrictions::AssertIOAllowed(); 594 ThreadRestrictions::AssertIOAllowed();
595 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), 595 base::win::ScopedHandle file(CreateFile(filename.value().c_str(),
596 GENERIC_WRITE, 596 GENERIC_WRITE,
597 0, 597 0,
598 NULL, 598 NULL,
599 CREATE_ALWAYS, 599 CREATE_ALWAYS,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 // Like Move, this function is not transactional, so we just 780 // Like Move, this function is not transactional, so we just
781 // leave the copied bits behind if deleting from_path fails. 781 // leave the copied bits behind if deleting from_path fails.
782 // If to_path exists previously then we have already overwritten 782 // If to_path exists previously then we have already overwritten
783 // it by now, we don't get better off by deleting the new bits. 783 // it by now, we don't get better off by deleting the new bits.
784 } 784 }
785 return false; 785 return false;
786 } 786 }
787 787
788 } // namespace internal 788 } // namespace internal
789 } // namespace base 789 } // namespace base
OLDNEW
« base/file_util_unittest.cc ('K') | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698