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 26 matching lines...) Expand all Loading... | |
37 return NULL; | 37 return NULL; |
38 } | 38 } |
39 | 39 |
40 Error KernelHandle::Init(int open_flags) { | 40 Error KernelHandle::Init(int open_flags) { |
41 handle_attr_.flags = open_flags; | 41 handle_attr_.flags = open_flags; |
42 | 42 |
43 if ((open_flags & O_CREAT) == 0 && !node_->CanOpen(open_flags)) { | 43 if ((open_flags & O_CREAT) == 0 && !node_->CanOpen(open_flags)) { |
44 return EACCES; | 44 return EACCES; |
45 } | 45 } |
46 | 46 |
47 // Directories can only be opened read-only. | |
48 if ((open_flags & 3) != O_RDONLY && node_->IsaDir()) { | |
bradn
2014/10/20 17:17:34
There no constant for the 3?j
Sam Clegg
2014/10/20 17:36:16
Not that I could find.
| |
49 return EISDIR; | |
50 } | |
51 | |
47 if (open_flags & O_APPEND) { | 52 if (open_flags & O_APPEND) { |
48 Error error = node_->GetSize(&handle_attr_.offs); | 53 Error error = node_->GetSize(&handle_attr_.offs); |
49 if (error) | 54 if (error) |
50 return error; | 55 return error; |
51 } | 56 } |
52 | 57 |
53 return 0; | 58 return 0; |
54 } | 59 } |
55 | 60 |
56 Error KernelHandle::Seek(off_t offset, int whence, off_t* out_offset) { | 61 Error KernelHandle::Seek(off_t offset, int whence, off_t* out_offset) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 return ENOTSOCK; | 233 return ENOTSOCK; |
229 if (OpenMode() == O_RDONLY) | 234 if (OpenMode() == O_RDONLY) |
230 return EACCES; | 235 return EACCES; |
231 | 236 |
232 AUTO_LOCK(handle_lock_); | 237 AUTO_LOCK(handle_lock_); |
233 return sock->SendTo(handle_attr_, buf, len, flags, dest_addr, addrlen, | 238 return sock->SendTo(handle_attr_, buf, len, flags, dest_addr, addrlen, |
234 out_len); | 239 out_len); |
235 } | 240 } |
236 | 241 |
237 } // namespace nacl_io | 242 } // namespace nacl_io |
OLD | NEW |