-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libc] implement sys/uio/readv
#124718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] implement sys/uio/readv
#124718
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //===-- Implementation file for readv -------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #include "src/sys/uio/readv.h" | ||
| #include "src/__support/OSUtil/syscall.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/errno/libc_errno.h" | ||
RossComputerGuy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <sys/syscall.h> | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(ssize_t, readv, (int fd, const iovec *iov, int iovcnt)) { | ||
| long ret = LIBC_NAMESPACE::syscall_impl<long>(SYS_readv, fd, iov, iovcnt); | ||
| // On failure, return -1 and set errno. | ||
| if (ret < 0) { | ||
| libc_errno = static_cast<int>(-ret); | ||
| return -1; | ||
| } | ||
| // On success, return number of bytes read. | ||
| return static_cast<ssize_t>(ret); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Implementation header for readv -----------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC_SYS_UIO_READV_H | ||
| #define LLVM_LIBC_SRC_SYS_UIO_READV_H | ||
|
|
||
| #include "hdr/types/ssize_t.h" | ||
| #include "hdr/types/struct_iovec.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| ssize_t readv(int fd, const iovec *iov, int iovcnt); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_SYS_UIO_READV_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===-- Unittests for readv -----------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/fcntl/open.h" | ||
| #include "src/sys/uio/readv.h" | ||
| #include "src/unistd/close.h" | ||
| #include "test/UnitTest/ErrnoSetterMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
nickdesaulniers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; | ||
|
|
||
| TEST(LlvmLibcSysUioReadvTest, SmokeTest) { | ||
| int fd = LIBC_NAMESPACE::open("/dev/urandom", O_RDONLY); | ||
|
||
| ASSERT_THAT(fd, returns(GT(0)).with_errno(EQ(0))); | ||
| char buf0[2]; | ||
| char buf1[3]; | ||
| struct iovec iov[2]; | ||
| iov[0].iov_base = buf0; | ||
| iov[0].iov_len = 1; | ||
| iov[1].iov_base = buf1; | ||
| iov[1].iov_len = 2; | ||
| ASSERT_THAT(LIBC_NAMESPACE::readv(fd, iov, 2), | ||
| returns(EQ(3)).with_errno(EQ(0))); | ||
| ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort alphabetically, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.