Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/files/file.h" |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <stdint.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <unistd.h> |
| 12 | |
| 13 | #include "base/logging.h" |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 14 | #include "base/posix/eintr_wrapper.h" |
| 15 | #include "base/strings/utf_string_conversions.h" |
Scott Graham | 76a8dc7 | 2018-06-18 13:37:29 -0700 | [diff] [blame] | 16 | #include "util/build_config.h" |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 17 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 18 | namespace base { |
| 19 | |
| 20 | // Make sure our Whence mappings match the system headers. |
| 21 | static_assert(File::FROM_BEGIN == SEEK_SET && File::FROM_CURRENT == SEEK_CUR && |
| 22 | File::FROM_END == SEEK_END, |
| 23 | "whence mapping must match the system headers"); |
| 24 | |
| 25 | namespace { |
| 26 | |
| 27 | #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) || \ |
| 28 | defined(OS_ANDROID) && __ANDROID_API__ < 21 |
Scott Graham | 98cd3ca | 2018-06-14 22:26:55 -0700 | [diff] [blame] | 29 | int CallFstat(int fd, stat_wrapper_t* sb) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 30 | return fstat(fd, sb); |
| 31 | } |
| 32 | #else |
Scott Graham | 98cd3ca | 2018-06-14 22:26:55 -0700 | [diff] [blame] | 33 | int CallFstat(int fd, stat_wrapper_t* sb) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 34 | return fstat64(fd, sb); |
| 35 | } |
| 36 | #endif |
| 37 | |
| 38 | // NaCl doesn't provide the following system calls, so either simulate them or |
| 39 | // wrap them in order to minimize the number of #ifdef's in this file. |
| 40 | #if !defined(OS_NACL) && !defined(OS_AIX) |
| 41 | bool IsOpenAppend(PlatformFile file) { |
| 42 | return (fcntl(file, F_GETFL) & O_APPEND) != 0; |
| 43 | } |
| 44 | |
| 45 | int CallFtruncate(PlatformFile file, int64_t length) { |
| 46 | return HANDLE_EINTR(ftruncate(file, length)); |
| 47 | } |
| 48 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 49 | #if !defined(OS_FUCHSIA) |
| 50 | File::Error CallFcntlFlock(PlatformFile file, bool do_lock) { |
| 51 | struct flock lock; |
| 52 | lock.l_type = do_lock ? F_WRLCK : F_UNLCK; |
| 53 | lock.l_whence = SEEK_SET; |
| 54 | lock.l_start = 0; |
| 55 | lock.l_len = 0; // Lock entire file. |
| 56 | if (HANDLE_EINTR(fcntl(file, F_SETLK, &lock)) == -1) |
| 57 | return File::GetLastFileError(); |
| 58 | return File::FILE_OK; |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | #else // defined(OS_NACL) && !defined(OS_AIX) |
| 63 | |
| 64 | bool IsOpenAppend(PlatformFile file) { |
| 65 | // NaCl doesn't implement fcntl. Since NaCl's write conforms to the POSIX |
| 66 | // standard and always appends if the file is opened with O_APPEND, just |
| 67 | // return false here. |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | int CallFtruncate(PlatformFile file, int64_t length) { |
| 72 | NOTIMPLEMENTED(); // NaCl doesn't implement ftruncate. |
| 73 | return 0; |
| 74 | } |
| 75 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 76 | File::Error CallFcntlFlock(PlatformFile file, bool do_lock) { |
| 77 | NOTIMPLEMENTED(); // NaCl doesn't implement flock struct. |
| 78 | return File::FILE_ERROR_INVALID_OPERATION; |
| 79 | } |
| 80 | #endif // defined(OS_NACL) |
| 81 | |
| 82 | } // namespace |
| 83 | |
| 84 | void File::Info::FromStat(const stat_wrapper_t& stat_info) { |
| 85 | is_directory = S_ISDIR(stat_info.st_mode); |
| 86 | is_symbolic_link = S_ISLNK(stat_info.st_mode); |
| 87 | size = stat_info.st_size; |
| 88 | |
Peter Collingbourne | 4dcd277 | 2019-02-05 22:24:34 -0800 | [diff] [blame^] | 89 | #if defined(OS_MACOSX) |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 90 | time_t last_modified_sec = stat_info.st_mtimespec.tv_sec; |
| 91 | int64_t last_modified_nsec = stat_info.st_mtimespec.tv_nsec; |
| 92 | time_t last_accessed_sec = stat_info.st_atimespec.tv_sec; |
| 93 | int64_t last_accessed_nsec = stat_info.st_atimespec.tv_nsec; |
| 94 | time_t creation_time_sec = stat_info.st_ctimespec.tv_sec; |
| 95 | int64_t creation_time_nsec = stat_info.st_ctimespec.tv_nsec; |
John Barboza | 499868c | 2018-07-18 22:58:30 -0400 | [diff] [blame] | 96 | #elif defined(OS_AIX) |
| 97 | time_t last_modified_sec = stat_info.st_mtime; |
| 98 | int64_t last_modified_nsec = 0; |
| 99 | time_t last_accessed_sec = stat_info.st_atime; |
| 100 | int64_t last_accessed_nsec = 0; |
| 101 | time_t creation_time_sec = stat_info.st_ctime; |
| 102 | int64_t creation_time_nsec = 0; |
Peter Collingbourne | 4dcd277 | 2019-02-05 22:24:34 -0800 | [diff] [blame^] | 103 | #elif defined(OS_POSIX) |
| 104 | time_t last_modified_sec = stat_info.st_mtim.tv_sec; |
| 105 | int64_t last_modified_nsec = stat_info.st_mtim.tv_nsec; |
| 106 | time_t last_accessed_sec = stat_info.st_atim.tv_sec; |
| 107 | int64_t last_accessed_nsec = stat_info.st_atim.tv_nsec; |
| 108 | time_t creation_time_sec = stat_info.st_ctim.tv_sec; |
| 109 | int64_t creation_time_nsec = stat_info.st_ctim.tv_nsec; |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 110 | #else |
Scott Graham | 622472c | 2018-06-14 16:53:22 -0700 | [diff] [blame] | 111 | #error |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 112 | #endif |
| 113 | |
Scott Graham | ce047c9 | 2018-06-19 15:56:56 -0700 | [diff] [blame] | 114 | constexpr uint64_t kNano = 1'000'000'000; |
| 115 | last_modified = last_modified_sec * kNano + last_modified_nsec; |
| 116 | last_accessed = last_accessed_sec * kNano + last_accessed_nsec; |
| 117 | creation_time = creation_time_sec * kNano + creation_time_nsec; |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | bool File::IsValid() const { |
| 121 | return file_.is_valid(); |
| 122 | } |
| 123 | |
| 124 | PlatformFile File::GetPlatformFile() const { |
| 125 | return file_.get(); |
| 126 | } |
| 127 | |
| 128 | PlatformFile File::TakePlatformFile() { |
| 129 | return file_.release(); |
| 130 | } |
| 131 | |
| 132 | void File::Close() { |
| 133 | if (!IsValid()) |
| 134 | return; |
| 135 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 136 | file_.reset(); |
| 137 | } |
| 138 | |
| 139 | int64_t File::Seek(Whence whence, int64_t offset) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 140 | DCHECK(IsValid()); |
| 141 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 142 | static_assert(sizeof(int64_t) == sizeof(off_t), "off_t must be 64 bits"); |
| 143 | return lseek(file_.get(), static_cast<off_t>(offset), |
| 144 | static_cast<int>(whence)); |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | int File::Read(int64_t offset, char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 148 | DCHECK(IsValid()); |
| 149 | if (size < 0) |
| 150 | return -1; |
| 151 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 152 | int bytes_read = 0; |
| 153 | int rv; |
| 154 | do { |
Scott Graham | 98cd3ca | 2018-06-14 22:26:55 -0700 | [diff] [blame] | 155 | rv = HANDLE_EINTR(pread(file_.get(), data + bytes_read, size - bytes_read, |
| 156 | offset + bytes_read)); |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 157 | if (rv <= 0) |
| 158 | break; |
| 159 | |
| 160 | bytes_read += rv; |
| 161 | } while (bytes_read < size); |
| 162 | |
| 163 | return bytes_read ? bytes_read : rv; |
| 164 | } |
| 165 | |
| 166 | int File::ReadAtCurrentPos(char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 167 | DCHECK(IsValid()); |
| 168 | if (size < 0) |
| 169 | return -1; |
| 170 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 171 | int bytes_read = 0; |
| 172 | int rv; |
| 173 | do { |
| 174 | rv = HANDLE_EINTR(read(file_.get(), data + bytes_read, size - bytes_read)); |
| 175 | if (rv <= 0) |
| 176 | break; |
| 177 | |
| 178 | bytes_read += rv; |
| 179 | } while (bytes_read < size); |
| 180 | |
| 181 | return bytes_read ? bytes_read : rv; |
| 182 | } |
| 183 | |
| 184 | int File::ReadNoBestEffort(int64_t offset, char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 185 | DCHECK(IsValid()); |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 186 | return HANDLE_EINTR(pread(file_.get(), data, size, offset)); |
| 187 | } |
| 188 | |
| 189 | int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 190 | DCHECK(IsValid()); |
| 191 | if (size < 0) |
| 192 | return -1; |
| 193 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 194 | return HANDLE_EINTR(read(file_.get(), data, size)); |
| 195 | } |
| 196 | |
| 197 | int File::Write(int64_t offset, const char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 198 | if (IsOpenAppend(file_.get())) |
| 199 | return WriteAtCurrentPos(data, size); |
| 200 | |
| 201 | DCHECK(IsValid()); |
| 202 | if (size < 0) |
| 203 | return -1; |
| 204 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 205 | int bytes_written = 0; |
| 206 | int rv; |
| 207 | do { |
| 208 | rv = HANDLE_EINTR(pwrite(file_.get(), data + bytes_written, |
| 209 | size - bytes_written, offset + bytes_written)); |
| 210 | if (rv <= 0) |
| 211 | break; |
| 212 | |
| 213 | bytes_written += rv; |
| 214 | } while (bytes_written < size); |
| 215 | |
| 216 | return bytes_written ? bytes_written : rv; |
| 217 | } |
| 218 | |
| 219 | int File::WriteAtCurrentPos(const char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 220 | DCHECK(IsValid()); |
| 221 | if (size < 0) |
| 222 | return -1; |
| 223 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 224 | int bytes_written = 0; |
| 225 | int rv; |
| 226 | do { |
Scott Graham | 98cd3ca | 2018-06-14 22:26:55 -0700 | [diff] [blame] | 227 | rv = HANDLE_EINTR( |
| 228 | write(file_.get(), data + bytes_written, size - bytes_written)); |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 229 | if (rv <= 0) |
| 230 | break; |
| 231 | |
| 232 | bytes_written += rv; |
| 233 | } while (bytes_written < size); |
| 234 | |
| 235 | return bytes_written ? bytes_written : rv; |
| 236 | } |
| 237 | |
| 238 | int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 239 | DCHECK(IsValid()); |
| 240 | if (size < 0) |
| 241 | return -1; |
| 242 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 243 | return HANDLE_EINTR(write(file_.get(), data, size)); |
| 244 | } |
| 245 | |
| 246 | int64_t File::GetLength() { |
| 247 | DCHECK(IsValid()); |
| 248 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 249 | stat_wrapper_t file_info; |
| 250 | if (CallFstat(file_.get(), &file_info)) |
| 251 | return -1; |
| 252 | |
| 253 | return file_info.st_size; |
| 254 | } |
| 255 | |
| 256 | bool File::SetLength(int64_t length) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 257 | DCHECK(IsValid()); |
| 258 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 259 | return !CallFtruncate(file_.get(), length); |
| 260 | } |
| 261 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 262 | bool File::GetInfo(Info* info) { |
| 263 | DCHECK(IsValid()); |
| 264 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 265 | stat_wrapper_t file_info; |
| 266 | if (CallFstat(file_.get(), &file_info)) |
| 267 | return false; |
| 268 | |
| 269 | info->FromStat(file_info); |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | #if !defined(OS_FUCHSIA) |
| 274 | File::Error File::Lock() { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 275 | return CallFcntlFlock(file_.get(), true); |
| 276 | } |
| 277 | |
| 278 | File::Error File::Unlock() { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 279 | return CallFcntlFlock(file_.get(), false); |
| 280 | } |
| 281 | #endif |
| 282 | |
| 283 | File File::Duplicate() const { |
| 284 | if (!IsValid()) |
| 285 | return File(); |
| 286 | |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 287 | PlatformFile other_fd = HANDLE_EINTR(dup(GetPlatformFile())); |
| 288 | if (other_fd == -1) |
| 289 | return File(File::GetLastFileError()); |
| 290 | |
| 291 | File other(other_fd); |
| 292 | if (async()) |
| 293 | other.async_ = true; |
| 294 | return other; |
| 295 | } |
| 296 | |
| 297 | // Static. |
| 298 | File::Error File::OSErrorToFileError(int saved_errno) { |
| 299 | switch (saved_errno) { |
| 300 | case EACCES: |
| 301 | case EISDIR: |
| 302 | case EROFS: |
| 303 | case EPERM: |
| 304 | return FILE_ERROR_ACCESS_DENIED; |
| 305 | case EBUSY: |
| 306 | #if !defined(OS_NACL) // ETXTBSY not defined by NaCl. |
| 307 | case ETXTBSY: |
| 308 | #endif |
| 309 | return FILE_ERROR_IN_USE; |
| 310 | case EEXIST: |
| 311 | return FILE_ERROR_EXISTS; |
| 312 | case EIO: |
| 313 | return FILE_ERROR_IO; |
| 314 | case ENOENT: |
| 315 | return FILE_ERROR_NOT_FOUND; |
| 316 | case ENFILE: // fallthrough |
| 317 | case EMFILE: |
| 318 | return FILE_ERROR_TOO_MANY_OPENED; |
| 319 | case ENOMEM: |
| 320 | return FILE_ERROR_NO_MEMORY; |
| 321 | case ENOSPC: |
| 322 | return FILE_ERROR_NO_SPACE; |
| 323 | case ENOTDIR: |
| 324 | return FILE_ERROR_NOT_A_DIRECTORY; |
| 325 | default: |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 326 | // This function should only be called for errors. |
| 327 | DCHECK_NE(0, saved_errno); |
| 328 | return FILE_ERROR_FAILED; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // NaCl doesn't implement system calls to open files directly. |
| 333 | #if !defined(OS_NACL) |
| 334 | // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? |
| 335 | void File::DoInitialize(const FilePath& path, uint32_t flags) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 336 | DCHECK(!IsValid()); |
| 337 | |
| 338 | int open_flags = 0; |
| 339 | if (flags & FLAG_CREATE) |
| 340 | open_flags = O_CREAT | O_EXCL; |
| 341 | |
| 342 | created_ = false; |
| 343 | |
| 344 | if (flags & FLAG_CREATE_ALWAYS) { |
| 345 | DCHECK(!open_flags); |
| 346 | DCHECK(flags & FLAG_WRITE); |
| 347 | open_flags = O_CREAT | O_TRUNC; |
| 348 | } |
| 349 | |
| 350 | if (flags & FLAG_OPEN_TRUNCATED) { |
| 351 | DCHECK(!open_flags); |
| 352 | DCHECK(flags & FLAG_WRITE); |
| 353 | open_flags = O_TRUNC; |
| 354 | } |
| 355 | |
| 356 | if (!open_flags && !(flags & FLAG_OPEN) && !(flags & FLAG_OPEN_ALWAYS)) { |
| 357 | NOTREACHED(); |
| 358 | errno = EOPNOTSUPP; |
| 359 | error_details_ = FILE_ERROR_FAILED; |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | if (flags & FLAG_WRITE && flags & FLAG_READ) { |
| 364 | open_flags |= O_RDWR; |
| 365 | } else if (flags & FLAG_WRITE) { |
| 366 | open_flags |= O_WRONLY; |
Scott Graham | 98cd3ca | 2018-06-14 22:26:55 -0700 | [diff] [blame] | 367 | } else if (!(flags & FLAG_READ) && !(flags & FLAG_WRITE_ATTRIBUTES) && |
| 368 | !(flags & FLAG_APPEND) && !(flags & FLAG_OPEN_ALWAYS)) { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 369 | NOTREACHED(); |
| 370 | } |
| 371 | |
| 372 | if (flags & FLAG_TERMINAL_DEVICE) |
| 373 | open_flags |= O_NOCTTY | O_NDELAY; |
| 374 | |
| 375 | if (flags & FLAG_APPEND && flags & FLAG_READ) |
| 376 | open_flags |= O_APPEND | O_RDWR; |
| 377 | else if (flags & FLAG_APPEND) |
| 378 | open_flags |= O_APPEND | O_WRONLY; |
| 379 | |
| 380 | static_assert(O_RDONLY == 0, "O_RDONLY must equal zero"); |
| 381 | |
| 382 | int mode = S_IRUSR | S_IWUSR; |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 383 | int descriptor = HANDLE_EINTR(open(path.value().c_str(), open_flags, mode)); |
| 384 | |
| 385 | if (flags & FLAG_OPEN_ALWAYS) { |
| 386 | if (descriptor < 0) { |
| 387 | open_flags |= O_CREAT; |
| 388 | if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE) |
Scott Graham | 98cd3ca | 2018-06-14 22:26:55 -0700 | [diff] [blame] | 389 | open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 390 | |
| 391 | descriptor = HANDLE_EINTR(open(path.value().c_str(), open_flags, mode)); |
| 392 | if (descriptor >= 0) |
| 393 | created_ = true; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | if (descriptor < 0) { |
| 398 | error_details_ = File::GetLastFileError(); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) |
| 403 | created_ = true; |
| 404 | |
| 405 | if (flags & FLAG_DELETE_ON_CLOSE) |
| 406 | unlink(path.value().c_str()); |
| 407 | |
| 408 | async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
| 409 | error_details_ = FILE_OK; |
| 410 | file_.reset(descriptor); |
| 411 | } |
| 412 | #endif // !defined(OS_NACL) |
| 413 | |
| 414 | bool File::Flush() { |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 415 | DCHECK(IsValid()); |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 416 | |
Scott Graham | 622472c | 2018-06-14 16:53:22 -0700 | [diff] [blame] | 417 | #if defined(OS_LINUX) |
Scott Graham | 6696211 | 2018-06-08 12:42:08 -0700 | [diff] [blame] | 418 | return !HANDLE_EINTR(fdatasync(file_.get())); |
| 419 | #else |
| 420 | return !HANDLE_EINTR(fsync(file_.get())); |
| 421 | #endif |
| 422 | } |
| 423 | |
| 424 | void File::SetPlatformFile(PlatformFile file) { |
| 425 | DCHECK(!file_.is_valid()); |
| 426 | file_.reset(file); |
| 427 | } |
| 428 | |
| 429 | // static |
| 430 | File::Error File::GetLastFileError() { |
| 431 | return base::File::OSErrorToFileError(errno); |
| 432 | } |
| 433 | |
| 434 | } // namespace base |