Index: native_client_sdk/src/libraries/nacl_io/kernel_handle.cc |
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc b/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc |
index dcf42fb8c6efa5a23692d7de4265f252cfaad5c3..8378ede26807dfba822d0ec12ef3f879ffc079da 100644 |
--- a/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc |
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_handle.cc |
@@ -17,17 +17,32 @@ |
#include "nacl_io/mount_node.h" |
// It is only legal to construct a handle while the kernel lock is held. |
-KernelHandle::KernelHandle(Mount* mnt, MountNode* node, int mode) |
+KernelHandle::KernelHandle(Mount* mnt, MountNode* node) |
: mount_(mnt), |
node_(node), |
- mode_(mode), |
offs_(0) { |
- if (mode & O_APPEND) offs_ = node->GetSize(); |
} |
-off_t KernelHandle::Seek(off_t offset, int whence) { |
+Error KernelHandle::Init(int open_mode) { |
+ if (open_mode & O_APPEND) { |
+ size_t node_size; |
+ Error error = node_->GetSize(&offs_); |
+ if (error) |
+ return error; |
+ } |
+ |
+ return 0; |
Sam Clegg
2013/05/31 18:40:29
Should you return a special value here, or 0 OK as
binji
2013/06/03 17:16:46
Yes, 0 is OK. AFAIK, there is no EOK, value and I
noelallen1
2013/06/07 21:48:43
If we do end up doing something interesting then
binji
2013/06/07 23:23:11
OK, I'll do that as part of the next CL.
|
+} |
+ |
+Error KernelHandle::Seek(off_t offset, int whence, off_t* out_offset) { |
+ // By default, don't move the offset. |
+ *out_offset = offset; |
+ |
size_t base; |
- size_t node_size = node_->GetSize(); |
+ size_t node_size; |
+ Error error = node_->GetSize(&node_size); |
+ if (error) |
+ return error; |
switch (whence) { |
default: return -1; |
@@ -36,21 +51,19 @@ off_t KernelHandle::Seek(off_t offset, int whence) { |
case SEEK_END: base = node_size; break; |
} |
- if (base + offset < 0) { |
- errno = EINVAL; |
- return -1; |
- } |
+ if (base + offset < 0) |
+ return EINVAL; |
- offs_ = base + offset; |
+ off_t new_offset = base + offset; |
// Seeking past the end of the file will zero out the space between the old |
// end and the new end. |
- if (offs_ > node_size) { |
- if (node_->FTruncate(offs_) < 0) { |
- errno = EINVAL; |
- return -1; |
- } |
+ if (new_offset > node_size) { |
+ error = node_->FTruncate(new_offset); |
+ if (error) |
+ return EINVAL; |
} |
- return offs_; |
+ *out_offset = offs_ = new_offset; |
+ return 0; |
} |