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