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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_handle.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/kernel_handle.h" 5 #include "nacl_io/kernel_handle.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 9
10 #include "nacl_io/mount.h" 10 #include "nacl_io/mount.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (error) 48 if (error)
49 return error; 49 return error;
50 } 50 }
51 51
52 return 0; 52 return 0;
53 } 53 }
54 54
55 Error KernelHandle::Seek(off_t offset, int whence, off_t* out_offset) { 55 Error KernelHandle::Seek(off_t offset, int whence, off_t* out_offset) {
56 // By default, don't move the offset. 56 // By default, don't move the offset.
57 *out_offset = offset; 57 *out_offset = offset;
58 size_t base; 58 ssize_t base;
59 size_t node_size; 59 size_t node_size;
60 60
61 AUTO_LOCK(handle_lock_); 61 AUTO_LOCK(handle_lock_);
62 Error error = node_->GetSize(&node_size); 62 Error error = node_->GetSize(&node_size);
63 if (error) 63 if (error)
64 return error; 64 return error;
65 65
66 switch (whence) { 66 switch (whence) {
67 default:
68 return -1;
69 case SEEK_SET: 67 case SEEK_SET:
70 base = 0; 68 base = 0;
71 break; 69 break;
72 case SEEK_CUR: 70 case SEEK_CUR:
73 base = handle_attr_.offs; 71 base = handle_attr_.offs;
74 break; 72 break;
75 case SEEK_END: 73 case SEEK_END:
76 base = node_size; 74 base = node_size;
77 break; 75 break;
76 default:
77 return -1;
78 } 78 }
79 79
80 if (base + offset < 0) 80 if (base + offset < 0)
81 return EINVAL; 81 return EINVAL;
82 82
83 off_t new_offset = base + offset; 83 size_t new_offset = base + offset;
84 84
85 // Seeking past the end of the file will zero out the space between the old 85 // Seeking past the end of the file will zero out the space between the old
86 // end and the new end. 86 // end and the new end.
87 if (new_offset > node_size) { 87 if (new_offset > node_size) {
88 error = node_->FTruncate(new_offset); 88 error = node_->FTruncate(new_offset);
89 if (error) 89 if (error)
90 return EINVAL; 90 return EINVAL;
91 } 91 }
92 92
93 *out_offset = handle_attr_.offs = new_offset; 93 *out_offset = handle_attr_.offs = new_offset;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return ENOTSOCK; 226 return ENOTSOCK;
227 if (OpenMode() == O_RDONLY) 227 if (OpenMode() == O_RDONLY)
228 return EACCES; 228 return EACCES;
229 229
230 AUTO_LOCK(handle_lock_); 230 AUTO_LOCK(handle_lock_);
231 return sock->SendTo(handle_attr_, buf, len, flags, dest_addr, addrlen, 231 return sock->SendTo(handle_attr_, buf, len, flags, dest_addr, addrlen,
232 out_len); 232 out_len);
233 } 233 }
234 234
235 } // namespace nacl_io 235 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/fifo_null.h ('k') | native_client_sdk/src/libraries/nacl_io/kernel_wrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698