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

Side by Side Diff: net/disk_cache/blockfile/mapped_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
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 "net/disk_cache/blockfile/mapped_file.h" 5 #include "net/disk_cache/blockfile/mapped_file.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/mman.h> 8 #include <sys/mman.h>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "net/disk_cache/disk_cache.h" 12 #include "net/disk_cache/disk_cache.h"
13 13
14 namespace disk_cache { 14 namespace disk_cache {
15 15
16 void* MappedFile::Init(const base::FilePath& name, size_t size) { 16 void* MappedFile::Init(const base::FilePath& name, size_t size) {
17 DCHECK(!init_); 17 DCHECK(!init_);
18 if (init_ || !File::Init(name)) 18 if (init_ || !File::Init(name))
19 return NULL; 19 return NULL;
20 20
21 size_t temp_len = size ? size : 4096; 21 size_t temp_len = size ? size : 4096;
22 if (!size) 22 if (!size) {
23 size = GetLength(); 23 size = GetLength();
24 if (!size)
25 return NULL;
danakj 2016/11/29 01:48:01 same same
26 }
24 27
25 buffer_ = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, 28 buffer_ = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
26 platform_file(), 0); 29 platform_file(), 0);
27 init_ = true; 30 init_ = true;
28 view_size_ = size; 31 view_size_ = size;
29 DPLOG_IF(FATAL, buffer_ == MAP_FAILED) << "Failed to mmap " << name.value(); 32 DPLOG_IF(FATAL, buffer_ == MAP_FAILED) << "Failed to mmap " << name.value();
30 if (buffer_ == MAP_FAILED) 33 if (buffer_ == MAP_FAILED)
31 buffer_ = 0; 34 buffer_ = 0;
32 35
33 // Make sure we detect hardware failures reading the headers. 36 // Make sure we detect hardware failures reading the headers.
(...skipping 11 matching lines...) Expand all
45 if (!init_) 48 if (!init_)
46 return; 49 return;
47 50
48 if (buffer_) { 51 if (buffer_) {
49 int ret = munmap(buffer_, view_size_); 52 int ret = munmap(buffer_, view_size_);
50 DCHECK_EQ(0, ret); 53 DCHECK_EQ(0, ret);
51 } 54 }
52 } 55 }
53 56
54 } // namespace disk_cache 57 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698