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

Side by Side Diff: base/platform_file_posix.cc

Issue 7821013: Base: Change ReadPlatformFile to perform a best (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/platform_file.h" 5 #include "base/platform_file.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 return descriptor; 142 return descriptor;
143 } 143 }
144 144
145 bool ClosePlatformFile(PlatformFile file) { 145 bool ClosePlatformFile(PlatformFile file) {
146 return !HANDLE_EINTR(close(file)); 146 return !HANDLE_EINTR(close(file));
147 } 147 }
148 148
149 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { 149 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) {
150 if (file < 0 || size < 0)
151 return -1;
152
153 int bytes_read = 0;
154 int rv;
155 do {
156 rv = HANDLE_EINTR(pread(file, data + bytes_read,
157 size - bytes_read, offset + bytes_read));
158 if (rv <= 0)
159 break;
160
161 bytes_read += rv;
162 } while (bytes_read < size);
163
164 return bytes_read ? bytes_read : rv;
165 }
166
167 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
168 char* data, int size) {
150 if (file < 0) 169 if (file < 0)
151 return -1; 170 return -1;
152 171
153 return HANDLE_EINTR(pread(file, data, size, offset)); 172 return HANDLE_EINTR(pread(file, data, size, offset));
154 } 173 }
155 174
156 int WritePlatformFile(PlatformFile file, int64 offset, 175 int WritePlatformFile(PlatformFile file, int64 offset,
157 const char* data, int size) { 176 const char* data, int size) {
158 if (file < 0 || size < 0) 177 if (file < 0 || size < 0)
159 return -1; 178 return -1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 info->is_directory = S_ISDIR(file_info.st_mode); 221 info->is_directory = S_ISDIR(file_info.st_mode);
203 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 222 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
204 info->size = file_info.st_size; 223 info->size = file_info.st_size;
205 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 224 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
206 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 225 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
207 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 226 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
208 return true; 227 return true;
209 } 228 }
210 229
211 } // namespace base 230 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698