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_proxy.h" | 5 #include "nacl_io/kernel_proxy.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 int KernelProxy::truncate(const char* path, off_t len) { | 785 int KernelProxy::truncate(const char* path, off_t len) { |
786 ScopedFilesystem fs; | 786 ScopedFilesystem fs; |
787 ScopedNode node; | 787 ScopedNode node; |
788 | 788 |
789 Error error = AcquireFsAndNode(path, O_WRONLY, 0, &fs, &node); | 789 Error error = AcquireFsAndNode(path, O_WRONLY, 0, &fs, &node); |
790 if (error) { | 790 if (error) { |
791 errno = error; | 791 errno = error; |
792 return -1; | 792 return -1; |
793 } | 793 } |
794 | 794 |
| 795 // Directories cannot be truncated. |
| 796 if (node->IsaDir()) { |
| 797 return EISDIR; |
| 798 } |
| 799 |
795 if (!node->CanOpen(O_WRONLY)) { | 800 if (!node->CanOpen(O_WRONLY)) { |
796 errno = EACCES; | 801 errno = EACCES; |
797 return -1; | 802 return -1; |
798 } | 803 } |
799 | 804 |
800 error = node->FTruncate(len); | 805 error = node->FTruncate(len); |
801 if (error) { | 806 if (error) { |
802 errno = error; | 807 errno = error; |
803 return -1; | 808 return -1; |
804 } | 809 } |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 errno = ENOTSOCK; | 1817 errno = ENOTSOCK; |
1813 return -1; | 1818 return -1; |
1814 } | 1819 } |
1815 | 1820 |
1816 return 0; | 1821 return 0; |
1817 } | 1822 } |
1818 | 1823 |
1819 #endif // PROVIDES_SOCKET_API | 1824 #endif // PROVIDES_SOCKET_API |
1820 | 1825 |
1821 } // namespace_nacl_io | 1826 } // namespace_nacl_io |
OLD | NEW |