| 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/files/file.h" | 5 #include "base/files/file.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 NOTIMPLEMENTED(); // NaCl doesn't implement flock struct. | 115 NOTIMPLEMENTED(); // NaCl doesn't implement flock struct. |
| 116 return File::FILE_ERROR_INVALID_OPERATION; | 116 return File::FILE_ERROR_INVALID_OPERATION; |
| 117 } | 117 } |
| 118 #endif // defined(OS_NACL) | 118 #endif // defined(OS_NACL) |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 // NaCl doesn't implement system calls to open files directly. | 122 // NaCl doesn't implement system calls to open files directly. |
| 123 #if !defined(OS_NACL) | 123 #if !defined(OS_NACL) |
| 124 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? | 124 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? |
| 125 void File::CreateBaseFileUnsafe(const FilePath& name, uint32 flags) { | 125 void File::InitializeUnsafe(const FilePath& name, uint32 flags) { |
| 126 base::ThreadRestrictions::AssertIOAllowed(); | 126 base::ThreadRestrictions::AssertIOAllowed(); |
| 127 DCHECK(!IsValid()); | 127 DCHECK(!IsValid()); |
| 128 DCHECK(!(flags & FLAG_ASYNC)); | 128 DCHECK(!(flags & FLAG_ASYNC)); |
| 129 | 129 |
| 130 int open_flags = 0; | 130 int open_flags = 0; |
| 131 if (flags & FLAG_CREATE) | 131 if (flags & FLAG_CREATE) |
| 132 open_flags = O_CREAT | O_EXCL; | 132 open_flags = O_CREAT | O_EXCL; |
| 133 | 133 |
| 134 created_ = false; | 134 created_ = false; |
| 135 | 135 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 334 |
| 335 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { | 335 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { |
| 336 base::ThreadRestrictions::AssertIOAllowed(); | 336 base::ThreadRestrictions::AssertIOAllowed(); |
| 337 DCHECK(IsValid()); | 337 DCHECK(IsValid()); |
| 338 if (size < 0) | 338 if (size < 0) |
| 339 return -1; | 339 return -1; |
| 340 | 340 |
| 341 return HANDLE_EINTR(write(file_, data, size)); | 341 return HANDLE_EINTR(write(file_, data, size)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 bool File::Truncate(int64 length) { | 344 int64 File::GetLength() { |
| 345 DCHECK(IsValid()); |
| 346 |
| 347 stat_wrapper_t file_info; |
| 348 if (CallFstat(file_, &file_info)) |
| 349 return false; |
| 350 |
| 351 return file_info.st_size; |
| 352 } |
| 353 |
| 354 bool File::SetLength(int64 length) { |
| 345 base::ThreadRestrictions::AssertIOAllowed(); | 355 base::ThreadRestrictions::AssertIOAllowed(); |
| 346 DCHECK(IsValid()); | 356 DCHECK(IsValid()); |
| 347 return !CallFtruncate(file_, length); | 357 return !CallFtruncate(file_, length); |
| 348 } | 358 } |
| 349 | 359 |
| 350 bool File::Flush() { | 360 bool File::Flush() { |
| 351 base::ThreadRestrictions::AssertIOAllowed(); | 361 base::ThreadRestrictions::AssertIOAllowed(); |
| 352 DCHECK(IsValid()); | 362 DCHECK(IsValid()); |
| 353 return !CallFsync(file_); | 363 return !CallFsync(file_); |
| 354 } | 364 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 return FILE_ERROR_FAILED; | 471 return FILE_ERROR_FAILED; |
| 462 } | 472 } |
| 463 } | 473 } |
| 464 | 474 |
| 465 void File::SetPlatformFile(PlatformFile file) { | 475 void File::SetPlatformFile(PlatformFile file) { |
| 466 DCHECK_EQ(file_, kInvalidPlatformFileValue); | 476 DCHECK_EQ(file_, kInvalidPlatformFileValue); |
| 467 file_ = file; | 477 file_ = file; |
| 468 } | 478 } |
| 469 | 479 |
| 470 } // namespace base | 480 } // namespace base |
| OLD | NEW |