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

Side by Side Diff: webrtc/system_wrappers/source/file_impl.cc

Issue 1714503003: Allow passing in strings of length zero to FileWrapper::Write without closing the file. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return false; 236 return false;
237 237
238 // Check if it's time to stop writing. 238 // Check if it's time to stop writing.
239 if (max_size_in_bytes_ > 0 && 239 if (max_size_in_bytes_ > 0 &&
240 (size_in_bytes_ + length) > max_size_in_bytes_) { 240 (size_in_bytes_ + length) > max_size_in_bytes_) {
241 FlushImpl(); 241 FlushImpl();
242 return false; 242 return false;
243 } 243 }
244 244
245 size_t num_bytes = fwrite(buf, 1, length, id_); 245 size_t num_bytes = fwrite(buf, 1, length, id_);
246 if (num_bytes > 0) { 246 size_in_bytes_ += num_bytes;
Henrik Grunell WebRTC 2016/02/19 15:04:38 Keep this inside the if block below. Not needed if
terelius 2016/02/19 16:50:29 By not closing the file, we can remove the entire
247 size_in_bytes_ += num_bytes; 247 if (num_bytes == length) {
Henrik Grunell WebRTC 2016/02/19 15:04:38 The original code is unclear. Good to change this.
terelius 2016/02/19 16:05:52 I agree on 1 and 3. I'd also prefer not closing th
248 return true; 248 return true;
249 } 249 }
250 250
251 CloseFileImpl(); 251 CloseFileImpl();
Henrik Grunell WebRTC 2016/02/19 15:04:38 Actually, do this if above condition isn't met ins
terelius 2016/02/19 16:50:29 By not closing the file, we can instead return the
Henrik Grunell WebRTC 2016/02/23 09:38:02 Does the file need to be closed elsewhere instead?
252 return false; 252 return false;
253 } 253 }
254 254
255 int FileWrapperImpl::CloseFileImpl() { 255 int FileWrapperImpl::CloseFileImpl() {
256 if (id_ != NULL) { 256 if (id_ != NULL) {
257 if (managed_file_handle_) 257 if (managed_file_handle_)
258 fclose(id_); 258 fclose(id_);
259 id_ = NULL; 259 id_ = NULL;
260 } 260 }
261 memset(file_name_utf8_, 0, kMaxFileNameSize); 261 memset(file_name_utf8_, 0, kMaxFileNameSize);
262 open_ = false; 262 open_ = false;
263 return 0; 263 return 0;
264 } 264 }
265 265
266 int FileWrapperImpl::FlushImpl() { 266 int FileWrapperImpl::FlushImpl() {
267 if (id_ != NULL) { 267 if (id_ != NULL) {
268 return fflush(id_); 268 return fflush(id_);
269 } 269 }
270 return -1; 270 return -1;
271 } 271 }
272 272
273 int FileWrapper::Rewind() { 273 int FileWrapper::Rewind() {
274 RTC_DCHECK(false); 274 RTC_DCHECK(false);
275 return -1; 275 return -1;
276 } 276 }
277 277
278 } // namespace webrtc 278 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698