OLD | NEW |
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) | 150 if (file < 0) |
151 return -1; | 151 return -1; |
152 | 152 |
153 return HANDLE_EINTR(pread(file, data, size, offset)); | 153 return HANDLE_EINTR(pread(file, data, size, offset)); |
154 } | 154 } |
155 | 155 |
156 int WritePlatformFile(PlatformFile file, int64 offset, | 156 int WritePlatformFile(PlatformFile file, int64 offset, |
157 const char* data, int size) { | 157 const char* data, int size) { |
158 if (file < 0) | 158 if (file < 0 || size < 0) |
159 return -1; | 159 return -1; |
160 | 160 |
161 return HANDLE_EINTR(pwrite(file, data, size, offset)); | 161 int bytes_written = 0; |
| 162 int rv; |
| 163 do { |
| 164 rv = HANDLE_EINTR(pwrite(file, data + bytes_written, |
| 165 size - bytes_written, offset + bytes_written)); |
| 166 if (rv <= 0) |
| 167 break; |
| 168 |
| 169 bytes_written += rv; |
| 170 } while (bytes_written < size); |
| 171 |
| 172 return bytes_written ? bytes_written : rv; |
162 } | 173 } |
163 | 174 |
164 bool TruncatePlatformFile(PlatformFile file, int64 length) { | 175 bool TruncatePlatformFile(PlatformFile file, int64 length) { |
165 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length))); | 176 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length))); |
166 } | 177 } |
167 | 178 |
168 bool FlushPlatformFile(PlatformFile file) { | 179 bool FlushPlatformFile(PlatformFile file) { |
169 return !HANDLE_EINTR(fsync(file)); | 180 return !HANDLE_EINTR(fsync(file)); |
170 } | 181 } |
171 | 182 |
(...skipping 19 matching lines...) Expand all Loading... |
191 info->is_directory = S_ISDIR(file_info.st_mode); | 202 info->is_directory = S_ISDIR(file_info.st_mode); |
192 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 203 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
193 info->size = file_info.st_size; | 204 info->size = file_info.st_size; |
194 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 205 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
195 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 206 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
196 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 207 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
197 return true; | 208 return true; |
198 } | 209 } |
199 | 210 |
200 } // namespace base | 211 } // namespace base |
OLD | NEW |