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 = -1; | |
163 while (bytes_written < size) { | |
164 rv = HANDLE_EINTR(pwrite(file, data + bytes_written, | |
165 size - bytes_written, offset + bytes_written)); | |
166 | |
167 if (rv <= 0) | |
168 break; | |
169 | |
170 bytes_written += rv; | |
171 } | |
172 | |
173 return bytes_written ? bytes_written : (size ? rv : 0); | |
Scott Hess - ex-Googler
2011/08/25 21:05:23
If !bytes_written && !size, then rv<=0, so I think
rvargas (doing something else)
2011/08/25 21:28:06
I want to return 0 instead of -1 (rv) if !size, an
Scott Hess - ex-Googler
2011/08/25 21:33:01
This means that the code changes to always return
rvargas (doing something else)
2011/08/25 21:37:50
No, that's not what I meant... fixing it.
| |
162 } | 174 } |
163 | 175 |
164 bool TruncatePlatformFile(PlatformFile file, int64 length) { | 176 bool TruncatePlatformFile(PlatformFile file, int64 length) { |
165 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length))); | 177 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length))); |
166 } | 178 } |
167 | 179 |
168 bool FlushPlatformFile(PlatformFile file) { | 180 bool FlushPlatformFile(PlatformFile file) { |
169 return !HANDLE_EINTR(fsync(file)); | 181 return !HANDLE_EINTR(fsync(file)); |
170 } | 182 } |
171 | 183 |
(...skipping 19 matching lines...) Expand all Loading... | |
191 info->is_directory = S_ISDIR(file_info.st_mode); | 203 info->is_directory = S_ISDIR(file_info.st_mode); |
192 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 204 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
193 info->size = file_info.st_size; | 205 info->size = file_info.st_size; |
194 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 206 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
195 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 207 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
196 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 208 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
197 return true; | 209 return true; |
198 } | 210 } |
199 | 211 |
200 } // namespace base | 212 } // namespace base |
OLD | NEW |