OLD | NEW |
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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 *error = PLATFORM_FILE_ERROR_FAILED; | 74 *error = PLATFORM_FILE_ERROR_FAILED; |
75 return kInvalidPlatformFileValue; | 75 return kInvalidPlatformFileValue; |
76 } | 76 } |
77 | 77 |
78 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { | 78 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { |
79 open_flags |= O_RDWR; | 79 open_flags |= O_RDWR; |
80 } else if (flags & PLATFORM_FILE_WRITE) { | 80 } else if (flags & PLATFORM_FILE_WRITE) { |
81 open_flags |= O_WRONLY; | 81 open_flags |= O_WRONLY; |
82 } else if (!(flags & PLATFORM_FILE_READ) && | 82 } else if (!(flags & PLATFORM_FILE_READ) && |
83 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && | 83 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && |
| 84 !(flags & PLATFORM_FILE_APPEND) && |
84 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { | 85 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { |
85 NOTREACHED(); | 86 NOTREACHED(); |
86 } | 87 } |
87 | 88 |
88 if (flags & PLATFORM_FILE_TERMINAL_DEVICE) | 89 if (flags & PLATFORM_FILE_TERMINAL_DEVICE) |
89 open_flags |= O_NOCTTY | O_NDELAY; | 90 open_flags |= O_NOCTTY | O_NDELAY; |
90 | 91 |
| 92 if (flags & PLATFORM_FILE_APPEND && flags & PLATFORM_FILE_READ) |
| 93 open_flags |= O_APPEND | O_RDWR; |
| 94 else if (flags & PLATFORM_FILE_APPEND) |
| 95 open_flags |= O_APPEND | O_WRONLY; |
| 96 |
91 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); | 97 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); |
92 | 98 |
93 int mode = S_IRUSR | S_IWUSR; | 99 int mode = S_IRUSR | S_IWUSR; |
94 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
95 mode |= S_IRGRP | S_IROTH; | 101 mode |= S_IRGRP | S_IROTH; |
96 #endif | 102 #endif |
97 | 103 |
98 int descriptor = | 104 int descriptor = |
99 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); | 105 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); |
100 | 106 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 base::ThreadRestrictions::AssertIOAllowed(); | 206 base::ThreadRestrictions::AssertIOAllowed(); |
201 if (file < 0 || size < 0) | 207 if (file < 0 || size < 0) |
202 return -1; | 208 return -1; |
203 | 209 |
204 return HANDLE_EINTR(read(file, data, size)); | 210 return HANDLE_EINTR(read(file, data, size)); |
205 } | 211 } |
206 | 212 |
207 int WritePlatformFile(PlatformFile file, int64 offset, | 213 int WritePlatformFile(PlatformFile file, int64 offset, |
208 const char* data, int size) { | 214 const char* data, int size) { |
209 base::ThreadRestrictions::AssertIOAllowed(); | 215 base::ThreadRestrictions::AssertIOAllowed(); |
| 216 |
| 217 if (fcntl(file, F_GETFL) & O_APPEND) |
| 218 return WritePlatformFileAtCurrentPos(file, data, size); |
| 219 |
210 if (file < 0 || size < 0) | 220 if (file < 0 || size < 0) |
211 return -1; | 221 return -1; |
212 | 222 |
213 int bytes_written = 0; | 223 int bytes_written = 0; |
214 int rv; | 224 int rv; |
215 do { | 225 do { |
216 rv = HANDLE_EINTR(pwrite(file, data + bytes_written, | 226 rv = HANDLE_EINTR(pwrite(file, data + bytes_written, |
217 size - bytes_written, offset + bytes_written)); | 227 size - bytes_written, offset + bytes_written)); |
218 if (rv <= 0) | 228 if (rv <= 0) |
219 break; | 229 break; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 default: | 339 default: |
330 #if !defined(OS_NACL) // NaCl build has no metrics code. | 340 #if !defined(OS_NACL) // NaCl build has no metrics code. |
331 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", | 341 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", |
332 saved_errno); | 342 saved_errno); |
333 #endif | 343 #endif |
334 return PLATFORM_FILE_ERROR_FAILED; | 344 return PLATFORM_FILE_ERROR_FAILED; |
335 } | 345 } |
336 } | 346 } |
337 | 347 |
338 } // namespace base | 348 } // namespace base |
OLD | NEW |