Chromium Code Reviews

Side by Side Diff: mojo/services/files/public/c/lib/file_fd_impl.cc

Issue 1397133002: Remove callers of mojo::Array<size_t> constructor in favor of ::New (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "files/public/c/lib/file_fd_impl.h" 5 #include "files/public/c/lib/file_fd_impl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 163 matching lines...)
174 errno_setter.Set(EINVAL); 174 errno_setter.Set(EINVAL);
175 return -1; 175 return -1;
176 } 176 }
177 177
178 if (!buf && count > 0) { 178 if (!buf && count > 0) {
179 errno_setter.Set(EFAULT); 179 errno_setter.Set(EFAULT);
180 return -1; 180 return -1;
181 } 181 }
182 182
183 // TODO(vtl): Is there a more natural (or efficient) way to do this? 183 // TODO(vtl): Is there a more natural (or efficient) way to do this?
184 mojo::Array<uint8_t> bytes_to_write(count); 184 auto bytes_to_write = mojo::Array<uint8_t>::New(count);
185 if (count > 0) 185 if (count > 0)
186 memcpy(&bytes_to_write[0], buf, count); 186 memcpy(&bytes_to_write[0], buf, count);
187 187
188 mojo::files::Error error = mojo::files::Error::INTERNAL; 188 mojo::files::Error error = mojo::files::Error::INTERNAL;
189 uint32_t num_bytes_written = 0; 189 uint32_t num_bytes_written = 0;
190 file_->Write(bytes_to_write.Pass(), 0, mojo::files::Whence::FROM_CURRENT, 190 file_->Write(bytes_to_write.Pass(), 0, mojo::files::Whence::FROM_CURRENT,
191 Capture(&error, &num_bytes_written)); 191 Capture(&error, &num_bytes_written));
192 if (!file_.WaitForIncomingResponse()) { 192 if (!file_.WaitForIncomingResponse()) {
193 errno_setter.Set(ESTALE); 193 errno_setter.Set(ESTALE);
194 return -1; 194 return -1;
(...skipping 80 matching lines...)
275 // Make up a value based on size. (Note: Despite the above "block size", this 275 // Make up a value based on size. (Note: Despite the above "block size", this
276 // block count is for 512-byte blocks!) 276 // block count is for 512-byte blocks!)
277 if (file_info->size > 0) 277 if (file_info->size > 0)
278 buf->st_blocks = (static_cast<mojio_blkcnt_t>(file_info->size) + 511) / 512; 278 buf->st_blocks = (static_cast<mojio_blkcnt_t>(file_info->size) + 511) / 512;
279 // Else leave |st_blocks| zero. 279 // Else leave |st_blocks| zero.
280 280
281 return true; 281 return true;
282 } 282 }
283 283
284 } // namespace mojio 284 } // namespace mojio
OLDNEW

Powered by Google App Engine