-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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 4 commits
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,29 @@ | ||
//===-- 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 "hdr/types/ssize_t.h" | ||
#include "hdr/types/struct_iovec.h" | ||
#include "src/__support/OSUtil/syscall.h" | ||
#include "src/__support/common.h" | ||
#include "src/errno/libc_errno.h" | ||
#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 |
---|---|---|
@@ -1,15 +1,33 @@ | ||
add_custom_target(libc_sys_uio_unittests) | ||
|
||
add_libc_unittest( | ||
writev_test | ||
SUITE | ||
libc_sys_uio_unittests | ||
libc_sys_uio_unittests | ||
SRCS | ||
writev_test.cpp | ||
DEPENDS | ||
libc.src.errno.errno | ||
libc.hdr.types.struct_iovec | ||
libc.src.__support.common | ||
libc.src.errno.errno | ||
libc.src.fcntl.open | ||
libc.src.sys.uio.writev | ||
libc.src.unistd.close | ||
libc.test.UnitTest.ErrnoSetterMatcher | ||
) | ||
|
||
add_libc_unittest( | ||
readv_test | ||
SUITE | ||
libc_sys_uio_unittests | ||
SRCS | ||
readv_test.cpp | ||
DEPENDS | ||
libc.hdr.types.struct_iovec | ||
libc.src.__support.common | ||
libc.src.errno.errno | ||
libc.src.fcntl.open | ||
libc.src.sys.uio.readv | ||
libc.src.unistd.close | ||
libc.test.UnitTest.ErrnoSetterMatcher | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===-- 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 "hdr/types/struct_iovec.h" | ||
#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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now that the existing libc/test/src/sys/uio/writev_test.cpp also opens /dev/random...but doesn't that mean these posix mandated functions won't run on windows? cc @SchrodingerZhu There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be more convenient to use an API like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think writing a sequence and reading it back is a better test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, let's get this fixed up first before landing then, please. Or at least file a bug saying this is an issue for the writev_test and readv_test, then add a link to that issue in a comment in both test files in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Switch to using local files. |
||
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()); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.