Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ set(TARGET_LIBC_ENTRYPOINTS

# wchar.h entrypoints
libc.src.wchar.wctob

# sys/uio.h entrypoints
libc.src.sys.uio.writev
)

if(LLVM_LIBC_INCLUDE_SCUDO)
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ set(TARGET_LIBC_ENTRYPOINTS
# wchar.h entrypoints
libc.src.wchar.wctob
libc.src.wchar.btowc

# sys/uio.h entrypoints
libc.src.sys.uio.writev
)

if(LLVM_LIBC_INCLUDE_SCUDO)
Expand Down
9 changes: 9 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,12 @@ add_proxy_header_library(
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.uid_t
)

add_proxy_header_library(
struct_iovec
HDRS
struct_iovec.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.struct_iovec
libc.include.sys_uio
)
21 changes: 21 additions & 0 deletions libc/hdr/types/struct_iovec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Proxy for struct iovec -------------------------------------------===//
//
// 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_HDR_TYPES_STRUCT_FLOCK64_H
#define LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK64_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/struct_iovec.h"

#else

#include <sys/uio.h>

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_STRUCT_FLOCK64_H
10 changes: 10 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,16 @@ add_header_macro(
.llvm-libc-types.struct_utsname
)

add_header_macro(
sys_uio
../libc/include/sys/uio.yaml
sys/uio.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.struct_iovec
.llvm-libc-types.ssize_t
)

add_header_macro(
sys_wait
../libc/include/sys/wait.yaml
Expand Down
16 changes: 16 additions & 0 deletions libc/include/sys/uio.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===-- POSIX header auxv.h -----------------------------------------------===//
//
// 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_SYS_UIO_H
#define LLVM_LIBC_SYS_UIO_H

#include "__llvm-libc-common.h"

%%public_api()

#endif // LLVM_LIBC_SYS_UIO_H
17 changes: 17 additions & 0 deletions libc/include/sys/uio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
header: sys/uio.h
header_template: uio.h.def
macros: []
types:
- type_name: struct_iovec
- type_name: ssize_t
enums: []
objects: []
functions:
- name: writev
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const struct iovec *
- type: int
1 change: 1 addition & 0 deletions libc/src/sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ add_subdirectory(statvfs)
add_subdirectory(utsname)
add_subdirectory(wait)
add_subdirectory(prctl)
add_subdirectory(uio)
10 changes: 10 additions & 0 deletions libc/src/sys/uio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()

add_entrypoint_object(
writev
ALIAS
DEPENDS
.${LIBC_TARGET_OS}.writev
)
14 changes: 14 additions & 0 deletions libc/src/sys/uio/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_entrypoint_object(
writev
SRCS
writev.cpp
HDRS
../writev.h
DEPENDS
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.__support.common
libc.src.errno.errno
libc.hdr.types.ssize_t
libc.hdr.types.struct_iovec
)
27 changes: 27 additions & 0 deletions libc/src/sys/uio/linux/writev.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation file for writev ------------------------------------===//
//
// 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/writev.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, writev, (int fd, const iovec *iov, int iovcnt)) {
long ret = LIBC_NAMESPACE::syscall_impl<long>(SYS_writev, 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 written.
return static_cast<ssize_t>(ret);
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/sys/uio/writev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Implementation header for writev ----------------------------------===//
//
// 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_WRITEV_H
#define LLVM_LIBC_SRC_SYS_UIO_WRITEV_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 writev(int fd, const iovec *iov, int iovcnt);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_SYS_UIO_WRITEV_H
1 change: 1 addition & 0 deletions libc/test/src/sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ add_subdirectory(wait)
add_subdirectory(prctl)
add_subdirectory(auxv)
add_subdirectory(epoll)
add_subdirectory(uio)
15 changes: 15 additions & 0 deletions libc/test/src/sys/uio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_custom_target(libc_sys_uio_unittests)
add_libc_unittest(
writev_test
SUITE
libc_sys_uio_unittests
SRCS
writev_test.cpp
DEPENDS
libc.src.errno.errno
libc.src.__support.common
libc.src.sys.uio.writev
libc.src.unistd.close
libc.src.fcntl.open
libc.test.UnitTest.ErrnoSetterMatcher
)
29 changes: 29 additions & 0 deletions libc/test/src/sys/uio/writev_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Unittests for writev ----------------------------------------------===//
//
// 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/writev.h"
#include "src/unistd/close.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;

TEST(LlvmLibcSysUioWritevTest, SmokeTest) {
int fd = LIBC_NAMESPACE::open("/dev/null", O_WRONLY);
ASSERT_THAT(fd, returns(GT(0)).with_errno(EQ(0)));
const char *data = "Hello, World!\n";
struct iovec iov[2];
iov[0].iov_base = const_cast<char *>(data);
iov[0].iov_len = 7;
iov[1].iov_base = const_cast<char *>(data + 7);
iov[1].iov_len = 8;
ASSERT_THAT(LIBC_NAMESPACE::writev(fd, iov, 2),
returns(EQ(15)).with_errno(EQ(0)));
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
}
Loading