[libc-commits] [libc] [libc] implement ioctl (PR #85890)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Wed Apr 10 12:45:17 PDT 2024
nickdesaulniers wrote:
Here are the changes I needed to make to make this compile and run successfully.
```diff
diff --git a/libc/src/sys/ioctl/linux/ioctl.cpp b/libc/src/sys/ioctl/linux/ioctl.cpp
index 6c8ff54dc2ae..f2354bcabb9c 100644
--- a/libc/src/sys/ioctl/linux/ioctl.cpp
+++ b/libc/src/sys/ioctl/linux/ioctl.cpp
@@ -20,10 +20,10 @@ namespace LIBC_NAMESPACE {
// madvise is to be supported on non-linux operating systems also.
LLVM_LIBC_FUNCTION(int, ioctl, (int fd, unsigned long request, ...)) {
va_list ptr_to_memory;
- va_start(ptr_to_memory, 1);
- va_arg(ptr_to_memory, void *) int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, request, ptr_to_memory);
+ va_start(ptr_to_memory, request);
+ va_arg(ptr_to_memory, void *);
va_end(ptr_to_memory);
+ int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, request, ptr_to_memory);
// A negative return value indicates an error with the magnitude of the
// value being the error code.
diff --git a/libc/test/src/sys/CMakeLists.txt b/libc/test/src/sys/CMakeLists.txt
index dc0aa8bf7b75..e80936514fc4 100644
--- a/libc/test/src/sys/CMakeLists.txt
+++ b/libc/test/src/sys/CMakeLists.txt
@@ -1,4 +1,8 @@
+add_subdirectory(auxv)
+add_subdirectory(epoll)
+add_subdirectory(ioctl)
add_subdirectory(mman)
+add_subdirectory(prctl)
add_subdirectory(random)
add_subdirectory(resource)
add_subdirectory(select)
@@ -8,6 +12,3 @@ add_subdirectory(stat)
add_subdirectory(statvfs)
add_subdirectory(utsname)
add_subdirectory(wait)
-add_subdirectory(prctl)
-add_subdirectory(auxv)
-add_subdirectory(epoll)
diff --git a/libc/test/src/sys/ioctl/linux/CMakeLists.txt b/libc/test/src/sys/ioctl/linux/CMakeLists.txt
index 93e68975c4e1..aa1bffec16bd 100644
--- a/libc/test/src/sys/ioctl/linux/CMakeLists.txt
+++ b/libc/test/src/sys/ioctl/linux/CMakeLists.txt
@@ -7,8 +7,7 @@ add_libc_unittest(
SRCS
ioctl_test.cpp
DEPENDS
- libc.include.sys_ioctl
+ libc.src.sys.ioctl.ioctl
libc.src.errno.errno
- libc.test.errno_setter_matcher
)
diff --git a/libc/test/src/sys/ioctl/linux/ioctl_test.cpp b/libc/test/src/sys/ioctl/linux/ioctl_test.cpp
index 3de3eff3e8d4..4fc76d1b3c18 100644
--- a/libc/test/src/sys/ioctl/linux/ioctl_test.cpp
+++ b/libc/test/src/sys/ioctl/linux/ioctl_test.cpp
@@ -22,6 +22,6 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
TEST(LlvmLibcIoctlTest, InvalidFileDescriptor) {
int fd = 10;
unsigned long request = 10;
- int res = LIBC_NAMESPACE::ioctl(fd, 10, NULL);
+ int res = LIBC_NAMESPACE::ioctl(fd, request, NULL);
EXPECT_THAT(res, Fails(EBADF, -1));
}
```
Please open a new PR with:
1. `git revert 3c2feab7d152b7f161b4adaecef4ec81f038a23e`. Use "Reland: [libc] implement ioctl (#85890)" as the commit one line description and when opening the PR.
2. add the changes I described above on top as a distinct commit, which will make it easier for reviewers to see what's new. Use `git clang-format HEAD~` to reformat it (since I did not)
Push that for review and tag us.
https://github.com/llvm/llvm-project/pull/85890
More information about the libc-commits
mailing list