base::ReadFile() should return the number of read bytes on Windows.

base::ReadFile() has inconsistent behavior between Linux/Mac and Windows.
When the passed |size| argument is larger than file's size, ReadFile() on Linux/Mac returns the number of read bytes, but ReadFile() on Windows returns -1.

We can workaround this behavior by calling GetFileSize() first, but there are already many clients which treat |size| as max size (They're passing the size of buffer).
I think we should make behavior on Windows be consistent with Linux/Mac.

BUG=243885
TEST=run base_unittests

Review URL: https://codereview.chromium.org/240893002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264768 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: d8b565d03c31de38052f98c64c73bdf8f55afe6a
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index e2eb2f8..f04053d 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -651,15 +651,15 @@
   return result;
 }
 
-int ReadFile(const FilePath& filename, char* data, int size) {
+int ReadFile(const FilePath& filename, char* data, int max_size) {
   ThreadRestrictions::AssertIOAllowed();
   int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
   if (fd < 0)
     return -1;
 
-  ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size));
-  if (int ret = IGNORE_EINTR(close(fd)) < 0)
-    return ret;
+  ssize_t bytes_read = HANDLE_EINTR(read(fd, data, max_size));
+  if (IGNORE_EINTR(close(fd)) < 0)
+    return -1;
   return bytes_read;
 }
 
@@ -670,8 +670,8 @@
     return -1;
 
   int bytes_written = WriteFileDescriptor(fd, data, size);
-  if (int ret = IGNORE_EINTR(close(fd)) < 0)
-    return ret;
+  if (IGNORE_EINTR(close(fd)) < 0)
+    return -1;
   return bytes_written;
 }
 
@@ -697,8 +697,8 @@
     return -1;
 
   int bytes_written = WriteFileDescriptor(fd, data, size);
-  if (int ret = IGNORE_EINTR(close(fd)) < 0)
-    return ret;
+  if (IGNORE_EINTR(close(fd)) < 0)
+    return -1;
   return bytes_written;
 }