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

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

Issue 700383007: Use implicit_cast<> instead of static_cast<> whenever possible (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month 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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // between WritableIoVec and iovec is that WritableIoVec’s iov_base is a 86 // between WritableIoVec and iovec is that WritableIoVec’s iov_base is a
87 // pointer to a const buffer, where iovec’s iov_base isn’t. writev doesn’t 87 // pointer to a const buffer, where iovec’s iov_base isn’t. writev doesn’t
88 // actually write to the data, so this cast is safe here. iovec’s iov_base is 88 // actually write to the data, so this cast is safe here. iovec’s iov_base is
89 // non-const because the same structure is used for readv and writev, and 89 // non-const because the same structure is used for readv and writev, and
90 // readv needs to write to the buffer that iov_base points to. 90 // readv needs to write to the buffer that iov_base points to.
91 iovec* iov = reinterpret_cast<iovec*>(&(*iovecs)[0]); 91 iovec* iov = reinterpret_cast<iovec*>(&(*iovecs)[0]);
92 size_t remaining_iovecs = iovecs->size(); 92 size_t remaining_iovecs = iovecs->size();
93 93
94 while (size > 0) { 94 while (size > 0) {
95 size_t writev_iovec_count = 95 size_t writev_iovec_count =
96 std::min(remaining_iovecs, static_cast<size_t>(IOV_MAX)); 96 std::min(remaining_iovecs, implicit_cast<size_t>(IOV_MAX));
97 ssize_t written = HANDLE_EINTR(writev(fd_.get(), iov, writev_iovec_count)); 97 ssize_t written = HANDLE_EINTR(writev(fd_.get(), iov, writev_iovec_count));
98 if (written < 0) { 98 if (written < 0) {
99 PLOG(ERROR) << "writev"; 99 PLOG(ERROR) << "writev";
100 return false; 100 return false;
101 } else if (written == 0) { 101 } else if (written == 0) {
102 LOG(ERROR) << "writev: returned 0"; 102 LOG(ERROR) << "writev: returned 0";
103 return false; 103 return false;
104 } 104 }
105 105
106 size -= written; 106 size -= written;
107 DCHECK_GE(size, 0); 107 DCHECK_GE(size, 0);
108 108
109 if (size == 0) { 109 if (size == 0) {
110 remaining_iovecs = 0; 110 remaining_iovecs = 0;
111 break; 111 break;
112 } 112 }
113 113
114 while (written > 0) { 114 while (written > 0) {
115 size_t wrote_this_iovec = 115 size_t wrote_this_iovec =
116 std::min(static_cast<size_t>(written), iov->iov_len); 116 std::min(implicit_cast<size_t>(written), iov->iov_len);
117 written -= wrote_this_iovec; 117 written -= wrote_this_iovec;
118 if (wrote_this_iovec < iov->iov_len) { 118 if (wrote_this_iovec < iov->iov_len) {
119 iov->iov_base = 119 iov->iov_base =
120 reinterpret_cast<char*>(iov->iov_base) + wrote_this_iovec; 120 reinterpret_cast<char*>(iov->iov_base) + wrote_this_iovec;
121 iov->iov_len -= wrote_this_iovec; 121 iov->iov_len -= wrote_this_iovec;
122 } else { 122 } else {
123 ++iov; 123 ++iov;
124 --remaining_iovecs; 124 --remaining_iovecs;
125 } 125 }
126 } 126 }
(...skipping 15 matching lines...) Expand all
142 142
143 off_t rv = lseek(fd_.get(), offset, whence); 143 off_t rv = lseek(fd_.get(), offset, whence);
144 if (rv < 0) { 144 if (rv < 0) {
145 PLOG(ERROR) << "lseek"; 145 PLOG(ERROR) << "lseek";
146 } 146 }
147 147
148 return rv; 148 return rv;
149 } 149 }
150 150
151 } // namespace crashpad 151 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698