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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/mount_node_mem.cc

Issue 73083005: [NaCl SDK] Enable linux host build for nacl_io and nacl_io_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "nacl_io/mount_node_mem.h" 5 #include "nacl_io/mount_node_mem.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 Error MountNodeMem::Write(const HandleAttr& attr, 54 Error MountNodeMem::Write(const HandleAttr& attr,
55 const void* buf, 55 const void* buf,
56 size_t count, 56 size_t count,
57 int* out_bytes) { 57 int* out_bytes) {
58 *out_bytes = 0; 58 *out_bytes = 0;
59 AUTO_LOCK(node_lock_); 59 AUTO_LOCK(node_lock_);
60 60
61 if (count == 0) 61 if (count == 0)
62 return 0; 62 return 0;
63 63
64 if (count + attr.offs > stat_.st_size) { 64 if (count + attr.offs > static_cast<size_t>(stat_.st_size)) {
65 Resize(count + attr.offs); 65 Resize(count + attr.offs);
66 count = stat_.st_size - attr.offs; 66 count = stat_.st_size - attr.offs;
67 } 67 }
68 68
69 memcpy(&data_[attr.offs], buf, count); 69 memcpy(&data_[attr.offs], buf, count);
70 *out_bytes = static_cast<int>(count); 70 *out_bytes = static_cast<int>(count);
71 return 0; 71 return 0;
72 } 72 }
73 73
74 Error MountNodeMem::FTruncate(off_t new_size) { 74 Error MountNodeMem::FTruncate(off_t new_size) {
75 AUTO_LOCK(node_lock_); 75 AUTO_LOCK(node_lock_);
76 Resize(new_size); 76 Resize(new_size);
77 return 0; 77 return 0;
78 } 78 }
79 79
80 void MountNodeMem::Resize(off_t new_size) { 80 void MountNodeMem::Resize(off_t new_size) {
81 if (new_size > data_.capacity()) { 81 if (new_size > static_cast<off_t>(data_.capacity())) {
82 // While the node size is small, grow exponentially. When it starts to get 82 // While the node size is small, grow exponentially. When it starts to get
83 // larger, grow linearly. 83 // larger, grow linearly.
84 size_t extra = std::min<size_t>(new_size, kMaxResizeIncrement); 84 size_t extra = std::min<size_t>(new_size, kMaxResizeIncrement);
85 data_.reserve(new_size + extra); 85 data_.reserve(new_size + extra);
86 } else if (new_size < stat_.st_size) { 86 } else if (new_size < stat_.st_size) {
87 // Shrink to fit. std::vector usually doesn't reduce allocation size, so 87 // Shrink to fit. std::vector usually doesn't reduce allocation size, so
88 // use the swap trick. 88 // use the swap trick.
89 std::vector<char>(data_).swap(data_); 89 std::vector<char>(data_).swap(data_);
90 } 90 }
91 data_.resize(new_size); 91 data_.resize(new_size);
92 stat_.st_size = new_size; 92 stat_.st_size = new_size;
93 } 93 }
94 94
95 } // namespace nacl_io 95 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/mount_node_http.cc ('k') | native_client_sdk/src/libraries/nacl_io/mount_node_tty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698