Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: base/files/file_posix.cc

Issue 2404823002: Fix error handling in POSIX version of the base::File::GetLength. (Closed)
Patch Set: Fix error handling in POSIX version of the base::File::GetLength. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/files/memory_mapped_file_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 9 #include <stdint.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 return HANDLE_EINTR(write(file_.get(), data, size)); 314 return HANDLE_EINTR(write(file_.get(), data, size));
315 } 315 }
316 316
317 int64_t File::GetLength() { 317 int64_t File::GetLength() {
318 DCHECK(IsValid()); 318 DCHECK(IsValid());
319 319
320 SCOPED_FILE_TRACE("GetLength"); 320 SCOPED_FILE_TRACE("GetLength");
321 321
322 stat_wrapper_t file_info; 322 stat_wrapper_t file_info;
323 if (CallFstat(file_.get(), &file_info)) 323 if (CallFstat(file_.get(), &file_info))
324 return false; 324 return -1;
325 325
326 return file_info.st_size; 326 return file_info.st_size;
327 } 327 }
328 328
329 bool File::SetLength(int64_t length) { 329 bool File::SetLength(int64_t length) {
330 ThreadRestrictions::AssertIOAllowed(); 330 ThreadRestrictions::AssertIOAllowed();
331 DCHECK(IsValid()); 331 DCHECK(IsValid());
332 332
333 SCOPED_FILE_TRACE_WITH_SIZE("SetLength", length); 333 SCOPED_FILE_TRACE_WITH_SIZE("SetLength", length);
334 return !CallFtruncate(file_.get(), length); 334 return !CallFtruncate(file_.get(), length);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 return !HANDLE_EINTR(fsync(file_.get())); 525 return !HANDLE_EINTR(fsync(file_.get()));
526 #endif 526 #endif
527 } 527 }
528 528
529 void File::SetPlatformFile(PlatformFile file) { 529 void File::SetPlatformFile(PlatformFile file) {
530 DCHECK(!file_.is_valid()); 530 DCHECK(!file_.is_valid());
531 file_.reset(file); 531 file_.reset(file);
532 } 532 }
533 533
534 } // namespace base 534 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/files/memory_mapped_file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698