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

Side by Side Diff: base/file_util_posix.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
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 <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <libgen.h> 10 #include <libgen.h>
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 644
645 FILE* OpenFile(const FilePath& filename, const char* mode) { 645 FILE* OpenFile(const FilePath& filename, const char* mode) {
646 ThreadRestrictions::AssertIOAllowed(); 646 ThreadRestrictions::AssertIOAllowed();
647 FILE* result = NULL; 647 FILE* result = NULL;
648 do { 648 do {
649 result = fopen(filename.value().c_str(), mode); 649 result = fopen(filename.value().c_str(), mode);
650 } while (!result && errno == EINTR); 650 } while (!result && errno == EINTR);
651 return result; 651 return result;
652 } 652 }
653 653
654 int ReadFile(const FilePath& filename, char* data, int size) { 654 int ReadFile(const FilePath& filename, char* data, int max_size) {
655 ThreadRestrictions::AssertIOAllowed(); 655 ThreadRestrictions::AssertIOAllowed();
656 int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY)); 656 int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
657 if (fd < 0) 657 if (fd < 0)
658 return -1; 658 return -1;
659 659
660 ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size)); 660 ssize_t bytes_read = HANDLE_EINTR(read(fd, data, max_size));
Mark Mentovai 2014/04/17 16:21:57 I kinda feel like if this was a short read but EOF
fukino 2014/04/18 02:22:12 Thank you for suggestion! I didn't realize any cas
661 if (int ret = IGNORE_EINTR(close(fd)) < 0) 661 if (int ret = IGNORE_EINTR(close(fd)) < 0)
Mark Mentovai 2014/04/17 16:21:57 You don’t need to track |ret| here, you can just
fukino 2014/04/18 02:22:12 Done for ReadFile(), WriteFile() and AppendToFile(
662 return ret; 662 return ret;
663 return bytes_read; 663 return bytes_read;
664 } 664 }
665 665
666 int WriteFile(const FilePath& filename, const char* data, int size) { 666 int WriteFile(const FilePath& filename, const char* data, int size) {
667 ThreadRestrictions::AssertIOAllowed(); 667 ThreadRestrictions::AssertIOAllowed();
668 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666)); 668 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666));
669 if (fd < 0) 669 if (fd < 0)
670 return -1; 670 return -1;
671 671
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 result = false; 890 result = false;
891 if (IGNORE_EINTR(close(outfile)) < 0) 891 if (IGNORE_EINTR(close(outfile)) < 0)
892 result = false; 892 result = false;
893 893
894 return result; 894 return result;
895 } 895 }
896 #endif // !defined(OS_MACOSX) 896 #endif // !defined(OS_MACOSX)
897 897
898 } // namespace internal 898 } // namespace internal
899 } // namespace base 899 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | base/file_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698