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

Side by Side Diff: util/file/file_reader.cc

Issue 1023943003: crashpad_database_util: Accept --new-report=- to read a new report from standard input (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@crashpad_database_util_new_report
Patch Set: Fix Windows Created 5 years, 4 months 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 | « util/file/file_reader.h ('k') | util/file/file_writer.h » ('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 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/file/file_reader.h" 15 #include "util/file/file_reader.h"
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
19 #include "build/build_config.h"
19 20
20 namespace crashpad { 21 namespace crashpad {
21 22
22 bool FileReaderInterface::ReadExactly(void* data, size_t size) { 23 bool FileReaderInterface::ReadExactly(void* data, size_t size) {
23 ssize_t expect = base::checked_cast<ssize_t>(size); 24 ssize_t expect = base::checked_cast<ssize_t>(size);
24 ssize_t rv = Read(data, size); 25 ssize_t rv = Read(data, size);
25 if (rv < 0) { 26 if (rv < 0) {
26 // Read() will have logged its own error. 27 // Read() will have logged its own error.
27 return false; 28 return false;
28 } else if (rv != expect) { 29 } else if (rv != expect) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ssize_t FileReader::Read(void* data, size_t size) { 91 ssize_t FileReader::Read(void* data, size_t size) {
91 DCHECK(file_.is_valid()); 92 DCHECK(file_.is_valid());
92 return weak_file_handle_file_reader_.Read(data, size); 93 return weak_file_handle_file_reader_.Read(data, size);
93 } 94 }
94 95
95 FileOffset FileReader::Seek(FileOffset offset, int whence) { 96 FileOffset FileReader::Seek(FileOffset offset, int whence) {
96 DCHECK(file_.is_valid()); 97 DCHECK(file_.is_valid());
97 return weak_file_handle_file_reader_.Seek(offset, whence); 98 return weak_file_handle_file_reader_.Seek(offset, whence);
98 } 99 }
99 100
101 WeakStdioFileReader::WeakStdioFileReader(FILE* file)
102 : file_(file) {
103 }
104
105 WeakStdioFileReader::~WeakStdioFileReader() {
106 }
107
108 ssize_t WeakStdioFileReader::Read(void* data, size_t size) {
109 DCHECK(file_);
110
111 size_t rv = fread(data, 1, size, file_);
112 if (rv < size && ferror(file_)) {
113 STDIO_PLOG(ERROR) << "fread";
114 return -1;
115 }
116
117 return rv;
118 }
119
120 FileOffset WeakStdioFileReader::Seek(FileOffset offset, int whence) {
121 DCHECK(file_);
122 if (fseeko(file_, offset, whence) == -1) {
123 STDIO_PLOG(ERROR) << "fseeko";
124 return -1;
125 }
126
127 FileOffset new_offset = ftello(file_);
128 if (new_offset == -1) {
129 STDIO_PLOG(ERROR) << "ftello";
130 return -1;
131 }
132
133 return new_offset;
134 }
135
100 } // namespace crashpad 136 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/file/file_reader.h ('k') | util/file/file_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698